簡體   English   中英

通過使用id的get元素,window.location無法正常工作

[英]window.location not working by using get element by id

您好我在下面的代碼中有一個新問題,在下面的代碼中window.location無法正常工作,盡管window.alert可以完美顯示我想要編寫此代碼的我想要的url和emailid值。 需要一點幫助,我是這個領域的新手。您的很少幫助將使我學得更好。

<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>

更新以響應正在編輯的問題:

如果希望將存儲在變量中的值連接起來,則需要使用實際的變量,而不是將代碼將它們連接到字符串文字中。

修改代碼如下,因為位置是屬性

window.location = cn.value + dn.value + ln.value; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM