2 回答
TA贡献1847条经验 获得超11个赞
分配c_id给您的输入框并将其传递给您的functionie:testfun()使用单击当前复选框this。如下所示:
Jsp代码:
out.print("<tr><td>"+"<input type='checkbox' name='a' value="+c_id+" onclick='testfun( this ,'"+c_id+"')'>"+"</td>" + "<td><input type='text' id='"+c_id+"' name='count' value=0 SIZE=5></td><td>"+name+"</td></tr> ");
JS代码:
function testfun(element, cName) {
var x = document.getElementById(cName);
//if check-box is checked
if (element.checked) {
//assign required value
x.value = 1;
} else {
x.value = 0;
}
}
演示代码:
function testfun(element, cName) {
var x = document.getElementById(cName);
//if check-box is checked
if (element.checked) {
//assign required value
x.value = 1;
} else {
x.value = 0;
} }
<input type="checkbox" name="abc" value="ddnd" onclick="testfun(this,'a')" />1
<input type="checkbox" name="abc" value="ddnd" onclick="testfun(this,'b')" />2
<input type="text" id="a" />
<input type="text" id="b" />
- 2 回答
- 0 关注
- 86 浏览
添加回答
举报