2011-09-08 79 views
0

如何在Jquery中勾選複選框時顯示提示框?當複選框未被選中時,警告框將消失。在Jquery中勾選複選框時顯示提示框

我試過下面的代碼,但它不起作用。誰能幫我嗎?謝謝!

<script type="text/javascript"> 
     $(document).ready(function(){ 

      if($('#chkAll').is(':checked')) 
      { 
       alert("im checked"); 

      } 

     }); 
     </script> 
<input id="chkAll" /> 

回答

3

嘗試

$(document).ready(function(){ 
    $('#chkAll').change(function() { 
     if($('#chkAll').is(':checked') { 
      alert("checked"); 
     } 
    }); 
}); 
0

您需要定義或者是改變或點擊功能來運行它,而不是你有什麼,該頁面加載後運行。

$(document).ready(function() { 
    $('#chkAll').change(function() { 
     alert($(this).val()); 
    }); 
}); 
0

該文檔只讀查看加載頁面時複選框的狀態。 觸發一個函數,當複選框觸發一個更改事件(當它被選中或未選中時)將一個事件監聽器綁定到它。

嘗試使用:

<script type="text/javascript"> 
$(document).ready(function(){ 

    $('#chkAll').bind('change', function() { 
     if($('#chkAll').is(':checked')) 
     { 
      alert("im checked"); 
     } 
    }); 

}); 
</script> 
1

你輸入需要一個複選框,實際做的東西你必須聽點擊或更改事件發生:

<script type="text/javascript"> 
    $(function(){ 
    $("#chkAll").bind("click",function(){ 
     if (this.checked) alert("I’m checked!"); 
    }); 
    }); 
</script> 
<input type="checkbox" id="chkAll" /> 

試試這個,看它是否工作!

1

試試這個。

$(document).ready(function(){ 
     //$('#chkAll').click(getCheck()); 
     $('#chkAll').click(function() { 
      if($('#chkAll').is(':checked')) 
       { 
        alert("im checked"); 
       } 
     }); 
    }); 


<input type="checkbox" id="chkAll" />