jQuery 勾选启用输入框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <label for="checks"> <input type="checkbox" name="checks" id="checks" value="1" /> <span>通过短信通知我</span> </label> <br /><br /> <div> 接收通知的手机号: <input id="exportInp" type="text" disabled="disabled" value="已禁用" /> <span style="color:#666;font-size:12px">请注意,有短信通知</span> </div> <script src="js/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ $("#checks").click(function(){ console.log($(this)+"点击我了"); // var checkeds = this.checked; if(this.checked == true){ console.log("选中了"); $("#exportInp").removeAttr("disabled"); }else{ console.log("未选中"); $("#exportInp").attr("disabled","disabled"); } }) }) </script> </body> </html>
效果预览: