想实现的功能:当我选择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>
2 回答
不负相思意
TA贡献1777条经验 获得超10个赞
一个例子:
<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>
- 2 回答
- 0 关注
- 459 浏览
添加回答
举报
0/150
提交
取消