用checkbox控制textbox是否可编辑,为什么隔一行才能控制.

想实现的功能:当我选择checkbox时,textbox编辑框可以编辑,取消选择时textbox不可以编辑,我js如下为什么隔一行才能控制,多谢各位帮忙。
JScript code
<script type="text/javascript">function contoltext(chkApproval) { var textall = document.getElementsByName("txtCharger"); var chkall = document.getElementsByName("chkApproval"); var nowtr = chkApproval.parentNode.parentNode.rowIndex; var j = (nowtr-1); if (chkall[j].checked) { textall[j].disabled =false; return; } elseif (!chkall[j].checked) { textall[j].disabled =true; } } </script>

 

HTML code
<tr><td ><%= Html.CheckBox("chkApproval", step.Approval, new { onclick ="contoltext(this)" })%><input type="text" id="txtCharger" disabled="disabled" name="txtCharger" onclick="dakai(this)" value="<%= step.Charger %>"/></td></tr><tr><td ><%= Html.CheckBox("chkApproval", step.Approval, new { onclick ="contoltext(this)" })%><input type="text" id="txtCharger" disabled="disabled" name="txtCharger" onclick="dakai(this)" value="<%= step.Charger %>"/></td></tr><tr><td ><%= Html.CheckBox("chkApproval", step.Approval, new { onclick ="contoltext(this)" })%><input type="text" id="txtCharger" disabled="disabled" name="txtCharger" onclick="dakai(this)" value="<%= step.Charger %>"/></td></tr><tr><td ><%= Html.CheckBox("chkApproval", step.Approval, new { onclick ="contoltext(this)" })%><input type="text" id="txtCharger" disabled="disabled" name="txtCharger" onclick="dakai(this)" value="<%= step.Charger %>"/></td></tr>
撒科打诨
浏览 461回答 2
2回答

不负相思意

一个例子: <html> <head> <script type="text/javascript" src="jquery-1.8.0.js"></script> </head> <body> <table> <tr> <td> <input type="checkbox"/> </td> <td> <input type="text" /> </td> </tr> <tr> <td> <input type="checkbox" /> </td> <td> <input type="text" /> </td> </tr> </table> </body> <script type="text/javascript"> $(function(){ $(":checkbox").click(function(){ if($(this).attr("checked")=="checked") { $($(this).parents("tr").find(":text").get(0)).attr("readonly","readonly"); } else { $($(this).parents("tr").find(":text").get(0)).removeAttr("readonly"); } }); }); </script> </html>

慕丝7291255

可以让一组中的CheckBox 的Id 与textbox的Id 联系起来。比如说 CheckBox1 选中 就可以变更textbox1
打开App,查看更多内容
随时随地看视频慕课网APP