代码不起作用

此代码对我不起作用.我只想在选中复选框时启用按钮.
请帮帮忙.

选择 | 换行 | 行号
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6.  
  7.  
  8. </head>
  9.  
  10. <body>
  11. <input id="agree" type="checkbox" />I agree<br />
  12. <input type="button" id="continue" value="continue" disabled="disabled">
  13. <script type="text/javascript" src="js/jQuery.js"></script>
  14. <script>
  15. $(document).ready(function(){
  16.     $('#agree').change(function(){
  17.              state = $(this).attr('value');
  18.             //alert(state);
  19.             if(state == 'on')
  20.             {
  21.                 $('#continue').removeAttr('disabled');
  22.             }
  23.             else if(state=='')
  24.             {
  25.                 $('#continue').attr('disabled','disabled');
  26.             }
  27.     });    
  28. });
  29. </script>
  30. </body>
  31. </html>
  32.  
# 回答1


请勿使用
Attr('Value')
.它接收复选框的初始状态(即JS
.defaultValue
财产).
裁判
使用
.val()
方法,而不是.
TBH,纯JavaScript在这里会更好/足够.
# 回答2


好的,谢谢..
但取消选中复选框后,它不会转到禁用该按钮的原始状态
# 回答3


你能详细说明一下吗?我不知道那是什么意思.

标签: Javascript

添加新评论