简体   繁体   English

使用javascript单击按钮后如何禁用特定表行中的复选框?

[英]How to disable checkbox in a specific table row after clicking a button using javascript?

I already have a code that works in disabling enabling elements after clicking a button. 我已经有一个代码,可以在单击按钮后禁用启用元素。 However, disabling a checkbox using addClass("disabled") is not working. 但是,使用addClass("disabled")禁用复选框不起作用。 How would I do that? 我该怎么做? Please take a look with my code below. 请看下面我的代码。 Thanks a lot. 非常感谢。

td:nth-child(3) and td:nth-child(4) is working fine but td:nth-child(1) checkbox disable is not working. td:nth-child(3)td:nth-child(4)正常工作,但td:nth-child(1)复选框禁用不起作用。

 $(document).on('click', '.generate', function(e){

        e.preventDefault();

          var $row = $(this).closest("tr"),

              $tds1 = $row.find("td:nth-child(1) input[type=checkbox].loan-id-checkbox").addClass("disabled");

              $tds3 = $row.find("td:nth-child(3) a.generate").addClass("disabled");
              $tds4 = $row.find("td:nth-child(4) a.btn-showAmort").removeClass("disabled");

      });

To disable a checkbox use the attribute disabled . 要禁用复选框,请使用属性disabled The css class will not have an effect. css类将无效。

$tds1 = $row.find("td:nth-child(1) input[type=checkbox].loan-id-checkbox").attr("disabled", true);

You don't just need to addClass for checkbox you need to set attribute to true for disabling the checkbox like this. 您不仅需要为复选框添加addClass,还需要将attribute设置为true来禁用这样的复选框。

 $row.find("td:nth-child(1) input[type=checkbox].loan-id-checkbox").addClass("disabled", true);
 OR
 $row.find("td:nth-child(1) input[type=checkbox].loan-id-checkbox").addClass("disabled",false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM