Javascript无法在复选框html5标记中使用 [英] Javascript not working in checkbox html5 tag
本文介绍了Javascript无法在复选框html5标记中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个代码,它将选中复选框并显示所选复选框的文本而不附加(暂时).Java脚本无效...错误是什么?
< 输入 id = Checkbox1 type = 复选框 / >
< 输入 id = Checkbox2 type = 复选框 / >
< label id = checktext > < / label >
java脚本是:
checktext.innerText = gettext(Checkbox1 ,Checkbox2);
function gettext(a,b){
var x = document.getElementById(a);
var y = document.getElementById(b);
if (x。已检查)
return x.textContent;
其他 如果(y。已检查)
return y.textContent;
}
解决方案
你' 在if语句中得到单等于而不是双等于:
if(checkbox.checked = true){
应该是
if(checkbox.checked == true){
或者只是
if(checkbox.checked){跨度>
I have written a code that will select the check box and display the text of selected checkbox without appending(time being).Java Script is not working... What is the error?
<input id="Checkbox1" type="checkbox" />
<input id="Checkbox2" type="checkbox" />
<label id="checktext"></label>
The java script is :
checktext.innerText = gettext("Checkbox1", "Checkbox2");
function gettext(a, b) {
var x = document.getElementById(a);
var y = document.getElementById(b);
if (x.checked)
return x.textContent;
else if (y.checked)
return y.textContent;
}
解决方案
You've got single-equals instead of double-equals in your if statements: if (checkbox.checked=true) { should be if (checkbox.checked == true) { or just if (checkbox.checked) {
这篇关于Javascript无法在复选框html5标记中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文