This is my HTML code:
<a id="id_1" name="n_1" href="#" onclick="callFn(this.id);">
<input type="checkbox" name="ck_1" id="xyz">
Click Here
</a>
I want to check this checkbox using Javascript code. How to do it??
答案 0 :(得分:1)
使用<label>
代替<a>
。
<label id="id_1" onclick="callFn(this.id);">
<input type="checkbox" name="ck_1" id="xyz">
Click Here
</labek>
这是<label>
标签的使用。此外,您根本不需要callFn(this.id);
。
答案 1 :(得分:0)
使用其ID document.getElementById("xyz")
然后将其属性checked
更改为true:
document.getElementById("xyz").checked = true;
答案 2 :(得分:0)
这是简单的 DEMO ..希望有所帮助
$("#check").click(function() {
var checkBoxes = $("#xyz");
checkBoxes.attr("checked", !checkBoxes.attr("checked"));
});
<label id="id_1" onclick="callFn(this.id);" for="xyz">
<input type="checkbox" name="ck_1" id="xyz">
Click Here
</labek>
<br/>
<button id="check">By button</button>