|zyciis| 求jquery 查询出没有for的label

zyciis282 2010-02-23 07:52:26

<label for="lbl1">1</label>
<label for="">2</label>
<label>3</label>
----------------------------
用Jquery找出第三个要怎么找,
要一次定位到

谢谢
...全文
149 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
上面写的ie6跟7应该有问题,修改下:

var res=$("label").filter(function(){
if((this.hasAttribute && !this.hasAttribute("for")) || (!this.getAttributeNode("for").specified))
return true;
}).html();
alert(res)
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
引用 7 楼 click_me 的回复:
那样麻烦了.
JScript code
$(function() {
alert($('label').not($('label[for]')).html())
});

ie7
Click_Me 2010-02-23
  • 打赏
  • 举报
回复
那样麻烦了.

$(function() {
alert($('label').not($('label[for]')).html())
});
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
引用 4 楼 zyciis282 的回复:
===
---------
javascript === 是什么意思?
alert(undefined==null)//判断值
alert(undefined===null)//===判断引用
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
var res=$("label").filter(function(){
if(this.hasAttribute && !this.hasAttribute("for") || this.getAttribute("for")===null)
//MSDN:If the attribute is not present, this method returns null.
//MDC:If the named attribute does not exist, the value returned will either be null or "" (the empty string);
//如果不考虑IE6可以直接使用hasAttribute判断
return true;
}).html();
alert(res)
zyciis282 2010-02-23
  • 打赏
  • 举报
回复
===
---------
javascript === 是什么意思?
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
var res=$("label").filter(function(){
if(this.getAttribute("for")===null)//If the attribute is not present, this method returns null.
return true;
}).html();
alert(res)
zyciis282 2010-02-23
  • 打赏
  • 举报
回复
<label>3 </label>
-----------
这个,
也就是没有注意for属性的label
谢谢
sohighthesky 2010-02-23
  • 打赏
  • 举报
回复
要找哪几个?

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧