jqery隐藏没有设置属性的层 如:<div>1</div><div class=2>2</div><div id="3">3</div>用jquery把1所在的层隐藏 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $("div:contains('1')").hide(); 笨方法:$("div"),然后遍历这个列表,取id和class,都没有的话就隐藏。没有设置属性,包括不包括其他attribute呢如果是那样,可以实时获取Attribute列表大小。为0就是没有一个属性。不过不知道是否都兼容。 你可以给1所在的层 添加一个class或者id属性,再来控制div层<div id="1">1</div><div class=2>2</div><div id="3">3</div><script type="text/javascript">$(function(){$("#1").hide();})</script> 楼主的重点是“没有设置属性”,这个jquery里真不知道有什么直接的方法可以获取,楼下高手继续。 也许我说的不够清楚,是隐藏像这样<div></div>没有设置属性的所有层如:<div>1</div> //第1个层<div class=2>2</div> //第2个层<div id="3">3</div> //第3个层<div>4</div> //第4个层<div>5</div> //第5个层隐藏第1、4、5层,层里面的数据是不确定的 $("div").each(function(){ if (!this.attributes.length){ $(this).hide(); } }) 这个在ff下 可以 ,但是不兼容ie 被迫搜了下,楼主可以看看下面的代码,兼容ie和ff<html><head><script src='http://code.jquery.com/jquery-latest.js'></script><script>$(function(){ var wori=$('div')[0].attributes for (var i=0;i<wori.length;i++){ if (wori[i].specified) alert('getit') } })</script></head><body><div id='a'>111</div></body></html> 很好。补充一下 $('div').each(function(){ var o = this.attributes; for( var i = 0; i < o.length; i++ ){ if ( o[i].specified ){ $(this).hide() } } }) OleDbDataAdapter.Fill( )模糊查询百万级数据导致内存溢出如何解决? JS有没有办法调用系统的右键菜单?? javascript字符串赋值出错 急,我该怎么办? iframe 的嵌入问题!~~~~ 日期验证谢谢了 在子窗体怎么给主窗体传参数? 一个form里有20个checkbox,怎样在提交的时候判断如果选定的超过10个,提示用户 请问input里class属性的用法 作用? 不能上网时,Ext页面显示异常 怎么用JQuery控制button按钮禁用?
$("div:contains('1')").hide();
没有设置属性,包括不包括其他attribute呢如果是那样,可以实时获取Attribute列表大小。为0就是没有一个属性。
不过不知道是否都兼容。
<div id="1">1</div>
<div class=2>2</div>
<div id="3">3</div>
<script type="text/javascript">
$(function(){
$("#1").hide();
})
</script>
如:
<div>1</div> //第1个层
<div class=2>2</div> //第2个层
<div id="3">3</div> //第3个层
<div>4</div> //第4个层
<div>5</div> //第5个层
隐藏第1、4、5层,层里面的数据是不确定的
$("div").each(function(){
if (!this.attributes.length){
$(this).hide();
}
})
这个在ff下 可以 ,但是不兼容ie
<html>
<head>
<script src='http://code.jquery.com/jquery-latest.js'></script>
<script>
$(function(){
var wori=$('div')[0].attributes
for (var i=0;i<wori.length;i++){
if (wori[i].specified)
alert('getit')
}
})
</script>
</head>
<body>
<div id='a'>111</div>
</body>
</html>
很好。
补充一下 $('div').each(function(){
var o = this.attributes;
for( var i = 0; i < o.length; i++ ){
if ( o[i].specified ){
$(this).hide()
}
}
})