javascript - 如果未选中复选框,则禁用按钮

标签 javascript jquery

我有一个从其余调用生成的下表结构,其中有输入复选框,在创建表之前,有一个静态按钮,除非单击任何复选框,否则我要禁用该按钮

<div id="divbuttons">
  <button id="Reject" type="button">Reject</button>
  <button id="Approve" type="button">Approve</button>
</div>

<table id="GetItems" cellspacing="12">
  <tbody>
   <tr style="background-color: rgb(204, 204, 204);">
    <td style="width: 349px;"><strong>Select</strong> 
       <input name="chk" type="checkbox" value="35">
    </td>
    <td style="width: 211px;">&nbsp;</td>
    <td style="width: 396px;"><strong>Requester: </strong>Test user</td>
    <td style="width: 149.2px;"><strong>Raised Date:</strong> 29/11/2017</td>
    <td style="width: 806.8px;" colspan="3">&nbsp;</td></tr><tr>
    <td style="width: 349px;"><strong>Item Requested For:<br>:</strong>Desktops</td>
    <td style="width: 211px;"><strong>Bomb<br>&nbsp;</strong>ITSS</td>
    <td style="width: 396px;"><strong>Department:</strong><br>ITSS Infrastructure</td>
    <td style="width: 149.2px;"><strong>Job Title:</strong><br>Consultant</td>
    <td style="width: 376.8px;"><strong>Phone Number:</strong><br>032394</td>
    <td style="width: 213px;"><strong>Request Type</strong><br>:New Allocation</td>
    <td style="width: 217px;"><strong>Replacement Type:<br></strong>New Allocation</td>
   </tr>
  </tbody>
</table>

如何使用 jQuery 实现此目的

最佳答案

试试这个代码:JSFiddle

$("input[name='chk']").on("change",function(){
   if(!$(this).is(':checked')) {
     $('#Reject').prop('disabled', true);
     $('#Approve').prop('disabled', true);
   } else {
    $('#Reject').prop('disabled', false);
    $('#Approve').prop('disabled', false);
   }
});

关于javascript - 如果未选中复选框,则禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47543684/

相关文章:

javascript - 如何从网页上的脚本加载外部 JSON?

Javascript 动态更新 CSS

javascript - 如何在点击次数后隐藏元素?

javascript - 将流类型 SuperType 的对象分配给 SubType 会导致错误

php - jQuery & PHP 和 MYSQL IE 问题

javascript - 如何在 Angular 中为 app.modules.ts 加载环境数据

javascript - 我的正则表达式适用于一行输入,但不适用于两行或更多...

javascript - 从具有特定 ID 的 Bootstrap DropDown 中获取选定的项目值

右侧的 jQuery Offcanvas 菜单

javascript - 在悬停 HTML 视频上使用自动播放在暂停时获取叠加层或占位符