2016-03-08 88 views
-2

我有一个复选框和我的asp.net网站中的按钮,按钮css属性设置为隐藏在页面的加载,在复选框我的帮助下要显示和隐藏asp.net按钮,问题是,该复选框被选中,但我不能够取消它.... plz帮助我有给代码复选框没有取消选中jquery的更改事件

<script> 
     $(function() { 
      $("#Btnforgotpass").css('display', 'none'); 
     }); 


     $(document).ready(function() { 


      $("[id$=chkforgotpass]").change(function() { 

       if (document.getElementById("chkforgotpass").checked = true) { 
        alert('checked'); 
        $("[id$=Btnforgotpass]").css('display', 'inline'); 

       } 
       else { 
        alert('unchecked'); 
        $("[id$=Btnforgotpass]").css('display', 'none'); 
       } 
      }); 
     }); 
</script> 
+2

你的if语句,尝试改变=到===要指定使用此语句 – user2950720

+0

感谢名单先生.....什么愚蠢的错误从我身边没有比较..... –

回答

0

你的if语句尝试改变=到===要指定使用此语句

$(function() { 
 
    $("#Btnforgotpass").css('display', 'none'); 
 
}); 
 

 

 
$(document).ready(function() { 
 

 

 
    $("[id$=chkforgotpass]").change(function() { 
 

 
    if (document.getElementById("chkforgotpass").checked === true) { 
 
     alert('checked'); 
 
     $("[id$=Btnforgotpass]").css('display', 'inline'); 
 

 
    } else { 
 
     alert('unchecked'); 
 
     $("[id$=Btnforgotpass]").css('display', 'none'); 
 
    } 
 
    }); 
 
});
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <script src="https://code.jquery.com/jquery-2.1.4.js"></script> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>JS Bin</title> 
 
</head> 
 

 
<body> 
 
    <button id="Btnforgotpass"> 
 
    Button 
 
    </button> 
 
    <input type="checkbox" id="chkforgotpass"> 
 
</body> 
 

 
</html>
0123没有比较

0

变化if (document.getElementById("chkforgotpass").checked = true) {if (document.getElementById("chkforgotpass").checked == true) {

如果你正在使用jQuery,实在是太简单的事情了。

$(document).ready(function() { 
    $("[id$=chkforgotpass]").change(function() { 
     var isChecked = $(this).is(":checked") : "inline" : "none"; 
     $("[id$=Btnforgotpass]").css('display', isChecked); 
    }); 
}); 
相关问题