2016-03-08 90 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); 
    }); 
}); 
相關問題