选中/取消选中按钮在jquery中不起作用

时间:2013-12-20 09:08:33

标签: javascript php jquery

   <img  onClick="return chkall()" id="btnchkall" name="btnchkall" class="submit_button" value="Check All"  src="images/check_all.jpg">
<img  onClick="return unchkall()" id="btnunchkall" name="btnunchkall" class="submit_button" value="Uncheck All"  src="images/uncheck_all.jpg">

function chkall() {
//  var status=$('#btnchkall').val();

        $('input[name="checkbox[]"]').attr('checked', true);
                $('#btnchkall').css('display','none');
                $('#btnunchkall').css('display','block');
        //$('#btnchkall').attr('alt','uncheckall');
//      $('#btnchkall').attr('value','un check');

}

function unchkall(){

$('input[name="checkbox[]"]').attr('checked', false);
$('#btnchkall').css('display','block');
$('#btnunchkall').css('display','none');

}



  <input type="checkbox" name="checkbox[]" class="chech_box"  value="<?php echo $value->intstatusid;?>">

当页面刷新时,它正在工作一次....之后就无法工作......

3 个答案:

答案 0 :(得分:0)

试试这个..

function chkall() {

            $('.chech_box').attr('checked', true);                    

    }

    function unchkall(){

     $('.chech_box').attr('checked', false);    

    }

答案 1 :(得分:0)

如果你使用jQuery 1.6+,你应该使用新的.prop()函数:

$('。submit_button')。prop('checked',true);
$('。submit_button')。prop('checked',false);

更多信息: http://api.jquery.com/prop/

答案 2 :(得分:0)

#Display seleted news in text field
if not True in user_selection:
      text_box.insert(0.0, "you need to select at least one news. ")
else: 
     if user_selection[0]:
         text_box.insert(END, "you select Education_Family. ")
     if user_selection[1]:
         text_box.insert(END, "you select Politics. ")
     if user_selection[2]:
         text_box.insert(END, "you select Science_Environment. ")
     if user_selection[3]:
         text_box.insert(END, "you select entertainment_Arts. ")

Screenshot of the code in action.