在初次加载页面的时候,html有去执行改段代码,把li列表中的复选框选中后变色
 jQuery(function ($) {
    //复选框选中的行指定背景色
            $('input[name="leimu"]').click(function (e) {
            if ($(this).attr('checked')) {
            $(this).parent().attr("style","background-color:red");
            } else {
            $(this).parent().attr("style","");
            }
            });
} 之后在执行页面上的搜索按钮查询后(click事件),然后再去点击页面上的列表中的复选框,没有执行上面那段代码了,背景色没有变化。怎样在click事情后也执行上面的方面,而不是只是在页面初次加载时执行

解决方案 »

  1.   

    给复选框也绑定上改变背景色的click事件
      

  2.   

    怎么让复选框也绑定上改变背景色的click事件。譬如点击搜索查询触发的函数是function temp_click(){
    } 。我把那段加在这个里面,在查询后点击复选框,还是没产生效果啊。
      

  3.   

    是不是$(this)也不同了 。
    input[name="leimu"]是复选框吧 ?
      

  4.   

    绑定上onchange或者onclik事件$("input[type='checkbox']").bind('click',function(){
                        if ($(this).attr('checked')) {
                            $(this).parent().attr("style", "background-color:red");
                        }
                        else {
                            $(this).parent().attr("style", "");
                        }
                        
                    });
      

  5.   

    if ($(this).attr('checked')) 貌似没有这样的判断吧
      

  6.   

    怎么判断复选框是不是选中,和让他的背景色变色呢?
    我这么写总是错的啊
     var checkbox1=document.getElementById("leimuId"); 
    var checkboxLis = checkbox1.getElementsByTagName("li"); 

    for(var i = 0; i < checkboxLis.length;i++){ 
        if (checkboxLis[i].checked == true) {
     checkboxLis[i].nextSibling.style.backgroundColor ="red";
               // checkboxLis[i].parent().attr("style","background-color:red");
                } else {
    alert(111);
               checkboxLis[i].nextSibling.style.backgroundColor ="white";
               // checkboxLis[i].parent().attr("style","");
                }
      

  7.   

    html是这样的,怎么判断的列表被选中和没有被选中啊
    <div id="checkbox">
              <ul style="list-style:none; line-height:16px; float:left; padding:0px; margin:0px;width:100%" id="leimuId">
    <li id="leimuchecked">
    <input name="leimu" type="checkbox" onclick="leimuselect()" value=\"\" />
    </li>
      </ul>
            </div>   
      

  8.   

    列表中的复选框选中,那么背景色改为红色,html是上面的,怎么写的啊?求教
      

  9.   

    $("#leimuchecked input [name='leimu']").each(function(){
         if($(this).attr("checked")){
                $(this).parent().css("color","red"); 
         }
    })