替换两个输入中的两个 document.write 值

发布于 2024-12-12 10:57:19 字数 1354 浏览 2 评论 0原文

下面的 JavaScript 将此值 http://www.google.co.uk/webhp?hl=en 替换为 http://link-ads.blogspot.com/?url=http输入条目上的 %3A%2F%2Fwww.google.co.uk%2Fwebhp%3Fhl%3Den

<script type="text/javascript">
function showMe(e) {
paramencode = encodeURIComponent(e.value)
document.write('http://link-ads.blogspot.com/?url='+paramencode+'');
}
</script>
<input type="text" id="foo" placeholder="URL here" onchange="showMe(this)" />

它工作正常,但我现在需要包含一个从第二个输入继承到文档写入末尾的 &name= + 值。

document.write('http://link-ads.blogspot.com/?url='+paramencode+'&name='+andnameinput+'');

其中 '+andnameinput+' 将从第二个

EDITED 继承值 如果我将 http://www.google.co.uk/webhp?hl=en 插入第一个输入,则

<input type="text" id="foo" placeholder="URL here"/>

document.write 的输出应为 http://link-ads .blogspot.com/?url=http%3A%2F%2Fwww.google.co.uk%2Fwebhp%3Fhl%3Den

但它不完整,因为它应该有 &name= 前面的用户输入值我需要一点时间输入

<input type="text" id="foo2" placeholder="Name here"/>

并说明如果输入值 123456789,则从 document.write 返回的输出应为 http://link-ads.blogspot.com/?url=http%3A%2F%2Fwww.google.co.uk %2Fwebhp%3Fhl%3Den&name=123456789

the javascript below replaces this value http://www.google.co.uk/webhp?hl=en with http://link-ads.blogspot.com/?url=http%3A%2F%2Fwww.google.co.uk%2Fwebhp%3Fhl%3Den on input entry.

<script type="text/javascript">
function showMe(e) {
paramencode = encodeURIComponent(e.value)
document.write('http://link-ads.blogspot.com/?url='+paramencode+'');
}
</script>
<input type="text" id="foo" placeholder="URL here" onchange="showMe(this)" />

It works fine but I now need to inclue an &name= + value inherited from second input to the end of the document write ie.

document.write('http://link-ads.blogspot.com/?url='+paramencode+'&name='+andnameinput+'');

where '+andnameinput+' will inherit the values from a second <input>

EDITED
if i insert http://www.google.co.uk/webhp?hl=en into the first input

<input type="text" id="foo" placeholder="URL here"/>

the output from the document.write should be http://link-ads.blogspot.com/?url=http%3A%2F%2Fwww.google.co.uk%2Fwebhp%3Fhl%3Den

but it is incomplete as it should have &name= infront with a user input value for that i need a second input

<input type="text" id="foo2" placeholder="Name here"/>

and say if the value 123456789 was input the output returned from the document.write should be http://link-ads.blogspot.com/?url=http%3A%2F%2Fwww.google.co.uk%2Fwebhp%3Fhl%3Den&name=123456789

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日落 2024-12-19 10:57:19

如果我理解得很好你想要这样的东西:

<script type="text/javascript">
    function showMe(e) {
        paramencode = encodeURIComponent(e.value)
        document.getElementById('urlEncoded').innerHTML = document.getElementById('urlEncoded').innerHTML + 'http://link-ads.blogspot.com/?url='+paramencode;
    }
    function UpdateParam() {
        document.getElementById('urlEncoded').innerHTML = document.getElementById('urlEncoded').innerHTML + '&name='+ document.getElementById('foo2').value;
    }
</script>
<div id="urlEncoded"></div>
<input type="text" id="foo" placeholder="URL here" onchange="showMe(this)" />
<input type="text" id="foo2" placeholder="SecondParam" onchange="UpdateParam()" />

If i understand well you want something like that:

<script type="text/javascript">
    function showMe(e) {
        paramencode = encodeURIComponent(e.value)
        document.getElementById('urlEncoded').innerHTML = document.getElementById('urlEncoded').innerHTML + 'http://link-ads.blogspot.com/?url='+paramencode;
    }
    function UpdateParam() {
        document.getElementById('urlEncoded').innerHTML = document.getElementById('urlEncoded').innerHTML + '&name='+ document.getElementById('foo2').value;
    }
</script>
<div id="urlEncoded"></div>
<input type="text" id="foo" placeholder="URL here" onchange="showMe(this)" />
<input type="text" id="foo2" placeholder="SecondParam" onchange="UpdateParam()" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文