dtqf81594 2013-09-15 16:33
浏览 43
已采纳

如何在jquery中启用/禁用特定表?

I have two tables in one form. I use jquery to enable/disable the text fields of both table separately. But when I click on one radio it enables/disables both the table text. Please help. A portion of code:

<div class="inputradio1">
  <input type="radio" id="radio" required="required" class="detailradio1" name="select1" Value="Yes" />Option 1<br/>
  <input type="radio" id="radio1" required="required" class="detailradio1" name="select1" value="No" />Option 2 
  </div>
 <script type="text/javascript">
         $("table :text").prop("disabled", true);
         $(".inputradio1 input[name=select1]").change(function () {
             $("table :text").prop('disabled', $(this).val() === 'No');
         });
</script>
<table>
    here is some text fields
</table>


<div class="inputradio2">
    <input type="radio" id="rad" required="required" class="detailradio2" name="select2" Value="Yes" />Fill<br/>
    <input type="radio" id="rad1" required="required" class="detailradio2" name="select2" value="No" />Leave <br/>
 </div>
<script type="text/javascript">
    $("table :text").prop("disabled", true);
    $(".inputradio2 input[name=select2]").change(function () {
       $("table :text").prop('disabled', $(this).val() === 'No');
    });
</script>
<table>
  here is some text fields
</table>

The problem is that if i click on the first radio button "Option 1" of first table it enables text fields of both tables and if i click on the first radio button "Option 2" of first table it disables text fields of both tables. I want to do the same thing but separately.

  • 写回答

1条回答 默认 最新

  • duanqianwei2485 2013-09-15 17:25
    关注

    you should give your tables class or id values end then add prop by them.

     <div class="inputradio1">
      <input type="radio" id="radio" required="required" class="detailradio1" name="select1" Value="Yes" />Option 1<br/>
      <input type="radio" id="radio1" required="required" class="detailradio1" name="select1" value="No" />Option 2 
      </div>
     <script type="text/javascript">
             $("table#table1 :text").prop("disabled", true);
             $(".inputradio1 input[name=select1]").change(function () {
                 $("table#table1 :text").prop('disabled', $(this).val() === 'No');
             });
    </script>
    <table id='table1'>
        here is some text fields
    </table>
    
    
    <div class="inputradio2">
        <input type="radio" id="radio" required="required" class="detailradio1" name="select2" Value="Yes" />Fill<br/>
        <input type="radio" id="radio1" required="required" class="detailradio1" name="select2" value="No" />Leave <br/>
     </div>
    <script type="text/javascript">
        $("table#table2 :text").prop("disabled", true);
        $(".inputradio2 input[name=select2]").change(function () {
           $("table#table2 :text").prop('disabled', $(this).val() === 'No');
        });
    </script>
    <table id="table2">
      here is some text fields
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态