jQuery中的DOM操作:如图是6行4列的列表(注意是表格),当点击某行任意元素(包括多选框或者后面的任意
答案:4 悬赏:70 手机版
解决时间 2021-12-01 14:58
- 提问者网友:贪了杯
- 2021-12-01 06:58
jQuery中的DOM操作:如图是6行4列的列表(注意是表格),当点击某行任意元素(包括多选框或者后面的任意
最佳答案
- 五星知识达人网友:思契十里
- 2021-12-01 08:23
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz |
这应该是你要的效果!
追问大神,厉害哦!不过好像不能同时勾选多个耶,怎样子可以实现能够同时勾选多个呢?追答
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz | |
xxx | yyy | zzz |
这应该是你要的效果!
全部回答
- 1楼网友:十年萤火照君眠
- 2021-12-01 10:14
$(function(){
$("table tr").click(function(event){
var target=event.target,
__chk = $("input:checkbox",this);
if(target.tagName.toLowerCase()=="input"){
target.checked=!target.checked;
}
if(!!__chk.attr("checked")){
__chk.removeAttr("checked");
this.style.backgroundColor = "yellow";
}else{
__chk.attr("checked","checked");
this.style.backgroundColor = "red";
$(this).siblings().css("backgroundColor","yellow").find("input:checkbox").removeAttr("checked");
}
});
});
$("table tr").click(function(event){
var target=event.target,
__chk = $("input:checkbox",this);
if(target.tagName.toLowerCase()=="input"){
target.checked=!target.checked;
}
if(!!__chk.attr("checked")){
__chk.removeAttr("checked");
this.style.backgroundColor = "yellow";
}else{
__chk.attr("checked","checked");
this.style.backgroundColor = "red";
$(this).siblings().css("backgroundColor","yellow").find("input:checkbox").removeAttr("checked");
}
});
});
aaaa | |
aaaa | |
aaaa | |
aaaa |
- 2楼网友:纵马山川剑自提
- 2021-12-01 09:17
$('tr').click(function(){with($(':checkbox',this)){attr('checked',!attr('checked'));}with($(this)){backgroundColor(backgroundColor()='red'?'green':'red');}});追问大神,可不可以给全部代码啊?追答这就是全部~追问亲,我要的是代码,可以直接运行的代码,你试过了吗?要包含 -->
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯