gpt4 book ai didi

javascript - window.location 无法通过使用 id 获取元素来工作

转载 作者:行者123 更新时间:2023-11-28 13:39:34 25 4
gpt4 key购买 nike

您好,我在下面的代码中提出了一个新问题,在下面的代码中 window.location 不起作用,尽管 window.alert 正在完美地显示我想要的我为其编写此代码的 emailid 的 url 和值。需要一点帮助,我是这个领域的新手。您的一点帮助会让我学得更好。提前致谢。

<html> 
<form>
<input id="c" type="hidden" value="http://mydomain.com"/>
<input id="d" type="hidden" value="/somefile.php?emailid=/>
<h5>Your Email adress</h5>
<br>
<input id="e" type="text"><br>
<input type="button" value="submit" onclick="display_alert();" />
</form>
<script lang="javascript">
function display_alert()
{ var dn = document.getElementById('d'); var cn = document.getElementById('c');
var fn = document.getElementById('a');
var ln = document.getElementById('e'); }
location = "cn.value + dn.value + ln.value";
</script>
</html>

最佳答案

location 不是函数。使用 = 为其赋值,不要使用 () 调用它。

<小时/>

或者完全删除对 JS 不必要的依赖:

<form action="http://mydomain.com/somefile.php">
<label>Your Email address
<input name="emailid"></label>
<input type="submit" value="submit">
</form>
<小时/>

针对正在编辑的问题进行更新:

如果您希望连接存储在变量中的值,那么您需要使用实际变量,而不是将它们连接到字符串文字中的代码。

关于javascript - window.location 无法通过使用 id 获取元素来工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18766290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com