- <script src1="http://code.jquery.com/jquery-1.8.1.min.js" ></script>
- <input type="checkbox" name="checkbox" id="checkbox_id1" value="1" onclick="test()" />1
- <script>
- function test(){
- //方法一
- console.log("1 "+$("#checkbox_id1").get(0).checked);
- if ($("#checkbox_id1").get(0).checked) {
- console.log(1);
- }
- //方法二
- console.log("2 "+$('#checkbox_id1').is(':checked'));
- if($('#checkbox_id1').is(':checked')) {
- console.log(2);
- }
- //方法三
- console.log("3 "+$('#checkbox_id1').prop('checked'));
- if ($('#checkbox_id1').prop('checked')) {
- console.log(3);
- }
- //方法四
- console.log("4 "+$('#checkbox_id1').attr('checked'));
- if ($('#checkbox_id1').attr('checked')) {
- console.log(4);
- }
- }
- </script>
- //该片段来自于http://www.codesnippet.cn/detail/1409201513677.html
来源: http://www.codesnippet.cn/detail/1409201513677.html