RadioButton控制一列的TextBox禁用或者启用,如图:

swazn_yj 2014-10-31 10:44:22
如图:


当一列上面的RadioButton按下后,其它列的TextBox禁用。
 <table width="90%" border="0" align="center" cellpadding="1">      
<tr>
<td class="auto-style6" style="text-decoration: underline">Cations</td>
<td class="auto-style3"><asp:RadioButton runat="server" ID="C_V1" Text="mg/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td class="auto-style4"><asp:RadioButton runat="server" ID="C_V2" Text="ppmm CaCo3" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td class="auto-style5"><asp:RadioButton runat="server" ID="C_V3" Text="meg/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td width="672"><asp:RadioButton runat="server" ID="C_V4" Text="mmol/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
</tr>
<tr>
<td align="right" class="auto-style6">Ammonium(NH4+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4">
<asp:TextBox ID="B_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5">
<asp:TextBox ID="C_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td>
<asp:TextBox ID="D_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Potassium(K+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Sodium(Na+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Magnesium(Mg2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6" style="color: #FF0000">*Calcium(Ca2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Strontium(Sr2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Barium(Ba2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Fe +x</td>
<td class="auto-style3">
<asp:TextBox ID="A_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Mn +x</td>
<td class="auto-style3">
<asp:TextBox ID="A_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Al 3+</td>
<td class="auto-style3">
<asp:TextBox ID="A_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
</table>


<script type="text/javascript">
function radionCheck(radioID) {
if (document.getElementById("C_V1").checked == true) {
document.getElementById('A_1').disabled = false;
document.getElementById('B_1').disabled = true;
document.getElementById('C_1').disabled = true;
document.getElementById('D_1').disabled = true;
document.getElementById('B_2').disabled = true;
document.getElementById('C_2').disabled = true;
}
else if (document.getElementById("C_V2").checked == true) {

}
else if (document.getElementById("C_V3").checked == true) {

}
else (document.getElementById("C_V4").checked == true) {

}
}
</script>


我这样写有点笨了,哪位大神能帮忙修改的简单些?
...全文
456 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2014-11-04
  • 打赏
  • 举报
回复
你用id选择器当然只能初始化一个了,改用其他可以选择多个对象的选择器,如样式选择器什么的 $("input.salary").blur(function(){ $(this).format({format:"###.000"}); }); <input type="text" class="salary"/> <input type="text" class="salary"/> <input type="text" class="salary"/> <input type="text" class="salary"/>
swazn_yj 2014-11-03
  • 打赏
  • 举报
回复
<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="js/jquery.numberformatter.js" type="text/javascript"></script>
<script src="js/jquery.alphanumeric.plus.js" type="text/javascript"></script>
<script>
$(document).ready(function() {

   $(".decimal").decimal();
   $(".numeric").numeric();

   $.fn.format.defaults.locale = "us";
   $.fn.parse.defaults.locale = "us";

   $("#salary").blur(function(){
      $(this).format({format:"###.000"});
   });  
});
</script>
我用这个来做验证挺好的,就是只能定义一个实例,怎么才能用到多个textbox上呢?而且还缺个弹出窗口提示功能,有没人办法搞定啊?大神!
swazn_yj 2014-10-31
  • 打赏
  • 举报
回复


我最终是要做两个类似的控制,这段代码能兼容吗?

引用 7 楼 showbo 的回复:
通过关系来获取


<script>
function radionCheck(rb) {
var cellIndex = rb.parentNode.cellIndex, input = rb.parentNode.parentNode.parentNode.getElementsByTagName('input');
for (var i = 0, j = input.length; i < j; i++)
input[i].disabled = input[i].type == 'text' && input[i].parentNode.cellIndex != cellIndex;
}
</script>
<table width="90%" border="0" align="center" cellpadding="1"><tbody>
<tr>
<td class="auto-style6" style="text-decoration: underline">Cations</td>
<td class="auto-style3"><asp:RadioButton runat="server" ID="C_V1" Text="mg/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td class="auto-style4"><asp:RadioButton runat="server" ID="C_V2" Text="ppmm CaCo3" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td class="auto-style5"><asp:RadioButton runat="server" ID="C_V3" Text="meg/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
<td width="672"><asp:RadioButton runat="server" ID="C_V4" Text="mmol/L" GroupName="1" onClick="radionCheck(this)"></asp:RadioButton></td>
</tr>
<tr>
<td align="right" class="auto-style6">Ammonium(NH4+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4">
<asp:TextBox ID="B_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5">
<asp:TextBox ID="C_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td>
<asp:TextBox ID="D_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Potassium(K+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Sodium(Na+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Magnesium(Mg2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6" style="color: #FF0000">*Calcium(Ca2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Strontium(Sr2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Barium(Ba2+)</td>
<td class="auto-style3">
<asp:TextBox ID="A_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Fe +x</td>
<td class="auto-style3">
<asp:TextBox ID="A_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Mn +x</td>
<td class="auto-style3">
<asp:TextBox ID="A_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr>
<tr>
<td align="right" class="auto-style6">Al 3+</td>
<td class="auto-style3">
<asp:TextBox ID="A_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
</td>
<td class="auto-style4"> <asp:TextBox ID="B_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td class="auto-style5"> <asp:TextBox ID="C_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
<td><asp:TextBox ID="D_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
</tr></tbody>
</table>
</form>
swsky 2014-10-31
  • 打赏
  • 举报
回复
 <script type="text/javascript">
        function radionCheck(radioID) {         
    
              for(i=1;i<=10;i++)
              {
                    document.getElementById('A_'+i).disabled = true;
                    document.getElementById('B_'+i).disabled = true;
                    document.getElementById('C_'+i).disabled = true;
                    document.getElementById('D_'+i).disabled = true;
                    document.getElementById(radioID.id + '_' + i).disabled = false;
                }
            }     
      
    </script>   
Go 旅城通票 2014-10-31
  • 打赏
  • 举报
回复
通过关系来获取
<script>
    function radionCheck(rb) {
        var cellIndex = rb.parentNode.cellIndex, input = rb.parentNode.parentNode.parentNode.getElementsByTagName('input');
        for (var i = 0, j = input.length; i < j; i++)
            input[i].disabled = input[i].type == 'text' && input[i].parentNode.cellIndex != cellIndex;
    }
</script>
<table width="90%" border="0" align="center" cellpadding="1"><tbody>
      <tr>
        <td class="auto-style6" style="text-decoration: underline">Cations</td>
        <td class="auto-style3"><asp:RadioButton runat="server" ID="C_V1" Text="mg/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td class="auto-style4"><asp:RadioButton runat="server" ID="C_V2" Text="ppmm CaCo3" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td class="auto-style5"><asp:RadioButton runat="server" ID="C_V3" Text="meg/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td width="672"><asp:RadioButton runat="server" ID="C_V4" Text="mmol/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Ammonium(NH4+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4">
          <asp:TextBox ID="B_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5">
          <asp:TextBox ID="C_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td>
          <asp:TextBox ID="D_1" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Potassium(K+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_2" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Sodium(Na+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_3" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Magnesium(Mg2+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_4" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6" style="color: #FF0000">*Calcium(Ca2+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_5" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr>
      <tr>
        <td align="right" class="auto-style6">Strontium(Sr2+)</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_6" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr>
      <tr>
        <td align="right" class="auto-style6">Barium(Ba2+)</td>
         <td class="auto-style3">
            <asp:TextBox ID="A_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_7" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr>
      <tr>
        <td align="right" class="auto-style6">Fe +x</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_8" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr>
      <tr>
        <td align="right" class="auto-style6">Mn +x</td>
        <td class="auto-style3">
            <asp:TextBox ID="A_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_9" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr>
      <tr>
        <td align="right" class="auto-style6">Al 3+</td>
       <td class="auto-style3">
            <asp:TextBox ID="A_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox>
            </td>
        <td class="auto-style4"> <asp:TextBox ID="B_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td class="auto-style5"> <asp:TextBox ID="C_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
        <td><asp:TextBox ID="D_10" runat="server" MaxLength="22" value="0.000"></asp:TextBox></td>
      </tr></tbody>
     </table>
</form>
  • 打赏
  • 举报
回复
简单示例,既然用了表格,那么你可以通过表格的列索引来控制,发挥表格的作用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$(function(){
	$('input[name="sel"]').click(function(){
		var col_index=0;
		if(this.checked)
		{
			col_index=$(this).parents("td").index();
			$(this).parents("tr").nextAll("tr").find("td").each(function(index, element) {
                if($(this).index()==col_index)
					$(this).find("input[type='text']").attr("disabled",false);
				else
					$(this).find("input[type='text']").attr("disabled",true);
            });;
		}
	});
})
</script>
</head>

<body>
<table>
	<tr>
		<td>Cations</td>
        <td><input type="radio" name="sel" id="sel_1"/><label for="sel_1">mg/L</label></td>
        <td><input type="radio" name="sel" id="sel_2"/><label for="sel_2">ppmm CaCo3</label></td>
        <td><input type="radio" name="sel" id="sel_3"/><label for="sel_3">meg/L</label></td>
        <td><input type="radio" name="sel" id="sel_4"/><label for="sel_4">mmol/L</label></td>
    </tr>
    <tr>
		<td>Ammonium(NH4+)</td>
        <td><input type="text" /></td>
        <td><input type="text" /></td>
        <td><input type="text" /></td>
        <td><input type="text"/></td>
    </tr>
    <tr>
		<td>Potassium(K+)</td>
        <td><input type="text" /></td>
        <td><input type="text" /></td>
        <td><input type="text" /></td>
        <td><input type="text"/></td>
    </tr>
</table>
</body>
</html>
slwsss 2014-10-31
  • 打赏
  • 举报
回复

<table width="90%" border="0" align="center" cellpadding="1">      
      <tr>
        <td class="auto-style6" style="text-decoration: underline">Cations</td>
        <td class="auto-style3"><input type="radio"/></td>
        <td class="auto-style4"><input type="radio"/></td>
        <td class="auto-style5"><input type="radio"/></td>
        <td width="672"><input type="radio"/></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Ammonium(NH4+)</td>
        <td class="auto-style3">
            <input type="text"/>
            </td>
        <td class="auto-style4"> <input type="text"/>/td>
        <td class="auto-style5"> <input type="text"/></td>
        <td> <input type="text"/></td>
        </tr>
      <tr>
        <td align="right" class="auto-style6">Potassium(K+)</td>
        <td class="auto-style3">
            <input type="text"/>
            </td>
        <td class="auto-style4">  <input type="text"/></td>
        <td class="auto-style5">  <input type="text"/></td>
        <td> <input type="text"/></td>
        </tr>
     </table>
$('table input[type=radio]').click(function(){ $('table input[type=text]').attr('disabled',true);var i=$('table input[type=radio]').index(this);$('table td:nth-child(6n+'+(i+2)+') input').attr('disabled',false); })
world_broken 2014-10-31
  • 打赏
  • 举报
回复
你确定你这样的JS能奏效?.net的服务器端控件在页面相应后,ID会变化的吧。给个思路你,用DIV遮罩,在table上套2个DIV(左右,第一行不要遮了),然后改变它们宽度。
swazn_yj 2014-10-31
  • 打赏
  • 举报
回复
我又修改了一下:
<tr>
        <td class="auto-style6" style="text-decoration: underline">Cations</td>
        <td class="auto-style3"><asp:RadioButton runat="server" ID="A" Text="mg/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td class="auto-style4"><asp:RadioButton runat="server" ID="B" Text="ppmm CaCo3" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td class="auto-style5"><asp:RadioButton runat="server" ID="C" Text="meg/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        <td width="672"><asp:RadioButton runat="server" ID="D" Text="mmol/L" GroupName="1"  onClick="radionCheck(this)"></asp:RadioButton></td>
        </tr>
<script type="text/javascript">
        function radionCheck(radioID) {
            alert(radioID);
              for(i=1;i<10;i++)
              {
                    document.getElementById('A_' + i).disabled = true;
                    document.getElementById('B_'+i).disabled = true;
                    document.getElementById('C_'+i).disabled = true;
                    document.getElementById('D_' + i).disabled = true;
                    document.getElementById(radioID + '_' + i).disabled = false;
                }
            }     
      
    </script>   
问题来了,怎么能传递到JS里RadioButton的ID号呢?
lcx411201851 2014-10-31
  • 打赏
  • 举报
回复
给每一列的 textbox一个class 用class 控制
Null_Reference 2014-10-31
  • 打赏
  • 举报
回复
用jquery 要简单些
Go 旅城通票 2014-10-31
  • 打赏
  • 举报
回复
blur的时候验证就好了吧,数据不对就不允许跳出输入框
<asp:TextBox ID="A_1" runat="server" MaxLength="22" value="0.000" onblur="validate(this)"></asp:TextBox>
<script type="text/javascript">
            function validate(tt){
                var val=tt.value;
                 var reg=/^\d+(.\d{1,3})?$/;
                if(!reg.test(val)){
                    alert("只能输入数字(最多三位小数)!");
                   tt.select()
                    return false;
                }
            }
        </script>
要不你的正则也有问题,输入1.的时候也不满足你的正则了。。其实用户还会继续输入什么的
swazn_yj 2014-10-31
  • 打赏
  • 举报
回复
楼上大神,能不能给个JS代码实时检查上面那些textbox只能输入数字且小数点后只能最多三位?
<script type="text/javascript">
            function validate(tt){
                var val=tt.value;
	             //var reg=/^(-?\d*)\.?\d{1,3}$/;
				 var reg=/^\d+(.\d{1,3})?$/;
                if(!reg.test(val)){
                    alert("只能输入数字(最多三位小数)!");
					event.keyCode=0;
                    document.getElementById(tt.id).focus();
                    return false;
                }
                //alert("good");
                return true;
            }
        </script>
<asp:TextBox ID="A_1" runat="server" MaxLength="22" value="0.000" onkeypress="validate(this)" onafterpaste="validate(this)"></asp:TextBox> 这样不行,我想要的结果是弹出提示,无效的输入被直接过滤,这个虽然弹出了但还能输入进去。
Go 旅城通票 2014-10-31
  • 打赏
  • 举报
回复
引用 11 楼 swazn_yj 的回复:
试了,可以用!
那个是靠dom关系来控制,多少个都行,只要你的结构不变
swazn_yj 2014-10-31
  • 打赏
  • 举报
回复
试了,可以用!
world_broken 2014-10-31
  • 打赏
  • 举报
回复
var ctlToElement=document.getElementById("<%=yourCtl.ClientID%>"); 然后就循环设置disable属性为true

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧