相关文章:

jQuery 选择器(:text)详解

代码类型:

杂项:

  • 启用CSS/JS语法检查
  • 监测脚本运行错误
  • 禁止库文件重复

文档类型:

JS库文件:

手动添加:

  1. jQuery 1.11.1
 
1
<div id="n1">
2
    <form id="n2">
3
       <input id="n3" type="button" value="Input Button"/>
4
       <input id="n4" type="checkbox" />
5
       <input id="n5" type="file" />
6
       <input id="n6" type="hidden" />
7
       <input id="n7" type="image" />
8
       <input id="n8" type="password" />
9
       <input id="n9" type="radio" />
10
       <input id="n10" type="reset" />  
11
       <input id="n11" type="submit" />
12
       <input id="n12" type="text" />
13
       <select id="n13">
14
        <option id="n14">Option</option>
15
       </select>
16
       <textarea id="n15"></textarea>
17
       <button id="n16">Button</button>
18
    </form>
19
</div>
xxxxxxxxxx
14
 
1
// 扩展jQuery对象,添加showTagInfo()方法
2
// 用于将jQuery对象所有匹配元素的标识信息追加到body元素内
3
// 每个元素的标识信息形如:"tagName"或"tagName#id"
4
jQuery.fn.showTagInfo = function(){
5
    var tags = this.map( function(){
6
        return this.tagName + ( this.id ? "#" + this.id : "" ); 
7
    } ).get();
8
    $("body").append( "<br>" + tags.join("<br>") + "<br>" );
9
};
10
11
12
13
// 选择了id为n12的一个元素
14
$(":text").showTagInfo();
x
 
1