f要禁用和启用复选框,请使用attr()
方法。
最初设置输入类型复选框并禁用它-
<input type="checkbox" id="sName" name= "Male" style="width: 25px" value="male" disabled="disabled"/>Male
现在单击按钮,在禁用和启用复选框之间切换-
$("#button1").click(function() { $("#sName").attr('disabled', !$("#sName").attr('disabled')); });
<html> <head> <title>jQuery Example</title> <script src = "https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function() { $("#sName").attr('disabled', !$("#sName").attr('disabled')); }); }); </script> </head> <body> <input type="checkbox" id="sName" name= "Male" style="width: 25px" value="male" disabled="disabled"/>Male <br> <br> <input type="button" id="button1" value="Disable/ Enable" /> </body> </html>