在初次加载页面的时候,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事情后也执行上面的方面,而不是只是在页面初次加载时执行
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事情后也执行上面的方面,而不是只是在页面初次加载时执行
} 。我把那段加在这个里面,在查询后点击复选框,还是没产生效果啊。
input[name="leimu"]是复选框吧 ?
if ($(this).attr('checked')) {
$(this).parent().attr("style", "background-color:red");
}
else {
$(this).parent().attr("style", "");
}
});
我这么写总是错的啊
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","");
}
}
<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>
if($(this).attr("checked")){
$(this).parent().css("color","red");
}
})