我现在有个table,每个tr中都有checkbox属性。现在有个过滤的函数过滤了部分tr之后剩余的tr全选,用document.getElementsByTagName("")不行啊,他会将过滤掉的那些tr也选中(我的过滤函数主要是设置style.display='none')。求大神帮忙看看啊!!js中到底有没有根据显示方式来选取元素的方法啊?
解决方案 »
- 谁能将下面代码做最小改动,实现将三个span居中放置在一个div中
- 求个兼容的写法
- fckEditor中获取文本编辑器中值的问题
- 鼠标定位问题?
- 我想实现每隔1秒运行某个函数1次,而且只运行5次,该怎么做?
- 向Myeclipse添加现有项目提示The following projects must be upgraded to work correctly with
- 采用hyperlinkcolumntanchu.弹出新窗口后,原页面变为空白,仅有[Object],
- 求一正则表达式的写法,请大家帮忙。。。。。。
- 给大家一个非常酷的代码,,同时放分 up
- 怎样判断输入的是整数而不是小数呢?望告知方法!
- canvas的toDataURL的问题
- jquery mousemove()在ie6下不停抖动,求教?
那你获取之后,根据这个加个逻辑判断进去就是了
比如,你先var trList=document.getElementsByTagName("tr");获取到了所有的tr
然后在遍历时增加判断
for(var i=0;i<trList.length;i++){
if(tr[i].style.display!='none'){
//这里面就是那些没有被你之前的过滤函数过滤掉的tr了
}
}
for(var i=0;i<trList.length;i++){
if(trList[i].style.display!='none'){
//这里面就是那些没有被你之前的过滤函数过滤掉的tr了
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript" src="/js/jquery-1.8.2.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(function(){
$("#checkAll").click(function(){
$("input[name='checkbox']").each(function(){
if($(this).css('display') != 'none'){
$(this).attr("checked", true);
}
});
});
});
</script>
</head>
<body>
<div>
<input type="button" name="checkAll" id="checkAll" value="check all">
<table id="mytable">
<tr>
<td>
<input type="checkbox" name="checkbox" value="11">
</td>
<td>
11
</td>
</tr>
<tr>
<td>
<input type="checkbox" style="display:none" name="checkbox" value="22">
</td>
<td>
22
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="checkbox" value="33">
</td>
<td>
33
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="checkbox" value="44">
</td>
<td>
44
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="checkbox" value="55">
</td>
<td>
55
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="checkbox" value="66">
</td>
<td>
66
</td>
</tr>
</table>
</div>
</body>
</html>
$("#checkAll").click(function(){
$("input[name='checkbox'][display!='none']").each(function(){
$(this).attr("checked", true);
});
});点击checkAll按钮时,让所有display不是none的checkbox的checked属性为真。
你全选所有checkbox,然后更具过滤条件去掉对应的checkbox的选中状态。
你全选所有checkbox,然后更具过滤条件去掉对应的checkbox的选中状态。