在初次加载页面的时候,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事情后也执行上面的方面,而不是只是在页面初次加载时执行
解决方案 »
- 关于 $("img",$self).attr("src","images/down.gif"); 这句话的疑问
- 为什么再减小的时候出错了
- 模态窗口问题,高手请进
- getElementById 提示'没有对象' 在线等
- 请问这句话是什么意思,执行结果是什么? eval("name=document.all.renyuanname"+id+".value");
- 求如何获取改变量的值
- 这样的脚本文件boolean1.0.js命名有问题?
- 关于在jsp中的javascript代码。
- 怎么区分窗口刷新与关闭窗口?!
- 高手。如何以打开页面就是chormless窗口
- IE9不支持SCRIPT脚本的SRC属性变更了
- viewport tabpanel一个显示问题
} 。我把那段加在这个里面,在查询后点击复选框,还是没产生效果啊。
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");
}
})