2016-08-03 88 views
0

愚蠢的小脚本在我添加2个复选框后无法正常工作。 目标是用一些动态参数打开一个URL。 我用Google搜索以查找可能的错误,但我没有找到。根据请求在脚本之前声明DOM属性。javascript复选框document.getElementById返回null

有什么想法吗?谢谢

<body> 
<table border="0"> 
    <tr> 
     <td>Serial Number</td> 
     <td><input type="text" id="deviceUdid" value="251528003720" maxlength="12" size="10"></td> 
    </tr> 
    <tr> 
     <td>HouseHold</td> 
     <td><input type="checkbox" id="Household" value="1"></tr> 
    <tr> 
     <td>Community</td> 
     <td><input type="checkbox" id="Communities"></tr> 
    <tr> 
     <td><input type="button" id="btn" value="Submit" onClick="form_submit()"></tr> 
</table> 

<script type="text/javascript"> 
    function form_submit() { 
     var a = 'https://test?'; 
     a += 'ACTION=authenticateUniqueDevice'; 
     a += '&deviceUdid=' + document.getElementById('deviceUdid').value; 
     a += '&CONTENT_READ_KEY=dddddddddd'; 
     if (document.getElementById('HouseHold').checked) a += '&includeHousehold=true'; 
     if (document.getElementById('Communities').checked) a += '&includeHouseholdCommunities=true'; 
     window.open(a, 'MyWindow', 'width=600,height=700'); 

    } 
</script> 

+0

并不完美......所以它是如何工作的,你怎么弄?你能指望什么? –

+2

HouseHold!==家庭 –

+0

开发者工具控制台日志将识别这个错字 –

回答

0

改变这一行(如下给出),似乎与案件HTML和脚本块之间的Household文字不同。

if (document.getElementById('Household').checked) a += '&includeHousehold=true'; 

修订后的脚本块

<script type="text/javascript"> 
    function form_submit() { 
     var a = 'https://test?'; 
     a += 'ACTION=authenticateUniqueDevice'; 
     a += '&deviceUdid=' + document.getElementById('deviceUdid').value; 
     a += '&CONTENT_READ_KEY=dddddddddd'; 
     if (document.getElementById('Household').checked) a += '&includeHousehold=true'; 
     if (document.getElementById('Communities').checked) a += '&includeHouseholdCommunities=true'; 
     window.open(a, 'MyWindow', 'width=600,height=700'); 

    } 
</script> 
+0

我真的很困惑,这个错字错误是愚蠢的。谢谢 ! – ThomasP

相关问题