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

zyciis282 2010-02-23 07:52:26

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

谢谢
...全文
138 9 打赏 收藏 举报
写回复
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
  • 打赏
  • 举报
回复
要找哪几个?
相关推荐
大多旅游网站上都提供了一个城市和日期输入查询的功能。用户在输入框中只需输入城市的拼音或者简称就可以即时查询到相关城市的名称,选择日期时则是现两个月的日历控件,只需点选日期即可,整个操作简捷明了。 本文用到了jquery ui库的datepicker插件来控制日历以及输入城市提示的插件。 XHTML
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2010-02-23 07:52
社区公告
暂无公告