我刚刚创建了一些自定义 JavaScript(起初),它生成了一个检查字段的总和。
但是,当我在 WordPress 中实现它时 - 它什么也不做。我想我忽略了一些东西,但我似乎无法弄清楚。
这是我的 JavaScript:
<script type="text/javascript">
<!--
function show_selected_item_val($item)
{
var res1 = 0, res2 = 0, res3 = 0, res4 = 0, res5 = 0, res6 = 0, res7 = 0, res8 = 0, res9 = 0, res10 = 0;
var res11 = 0, res12 = 0, res13 = 0, res14 = 0, res15 = 0, res16 = 0, res17 = 0, res18 = 0;
if(document.all['Q1'][0].checked) res1 = 1;
if(document.all['Q2'][0].checked) res2 = 1;
if(document.all['Q3'][0].checked) res3 = 1;
if(document.all['Q4'][0].checked) res4 = 1;
if(document.all['Q5'][0].checked) res5 = 1;
if(document.all['Q6'][0].checked) res6 = 1;
if(document.all['Q7'][0].checked) res7 = 1;
if(document.all['Q8'][0].checked) res8 = 1;
if(document.all['Q9'][0].checked) res9 = 1;
if(document.all['Q10'][0].checked) res10 = 1;
if(document.all['Q11'][0].checked) res11 = 1;
if(document.all['Q12'][0].checked) res12 = 1;
if(document.all['Q13'][0].checked) res13 = 1;
if(document.all['Q14'][0].checked) res14 = 1;
if(document.all['Q15'][0].checked) res15 = 1;
if(document.all['Q16'][0].checked) res16 = 1;
if(document.all['Q17'][0].checked) res17 = 1;
if(document.all['Q18'][0].checked) res18 = 1;
document.getElementById("show_content").innerHTML= res1 + res2 + res3 + res4 + res5 + res6 + res7 + res8 + res9 + res10 + res11 + res12 + res13 + res14 + res15 + res16 + res17 + res18;
}
//-->
</script>
这是 HTML:
<table>
<tr>
<td>
<input type="radio" name="Q1" value="1" onClick="show_selected_item_val(this)"/>yes
<input type="radio" name="Q1" value="0" onClick="show_selected_item_val(this)"/>no
</td>
</tr>
<tr>
<td>
<input type="radio" name="Q2" value="1" onClick="show_selected_item_val(this)"/>yes
<input type="radio" name="Q2" value="0" onClick="show_selected_item_val(this)"/>no
</td>
</tr>
<tr>
<td>
<input type="radio" name="Q3" value="1" onClick="show_selected_item_val(this)"/>yes
<input type="radio" name="Q3" value="0" onClick="show_selected_item_val(this)"/>no
</td>
</tr>
<tr>
<td>
<input type="radio" name="Q4" value="1" onClick="show_selected_item_val(this)"/>yes
<input type="radio" name="Q4" value="0" onClick="show_selected_item_val(this)"/>no
</td>
</tr>
...
</table>
the result is: <span id="show_content">
我正在通过functions.php
文件加载 JavaScript。我检查了,它确实加载了。结果只是不显示。
所以我猜脚本的处理是不正确的。
有什么建议么?