欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

jQuery 遍历 - add() 方法

shiping1 的头像

jQuery 遍历 - add() 方法

 

$(document).ready(function(){
     $('#swtIcon_Counter').add('#swtLinkCounter').text(num);
});
实例

找到所有 div 并添加边框。然后将所有段落添加到该 jQuery 对象,并把它们的背景设置为黄色:

$("div").css("border", "2px solid red")
        .add("p")
        .css("background", "yellow");

定义和用法

add() 方法将元素添加到匹配元素的集合中。

语法 1

.add(selector)
参数描述
selector字符串值,表示查找供添加到匹配元素集合的元素的选择器表达式。

语法 2

.add(elements)
参数描述
elements添加到匹配元素集合的一个或多个元素。

语法 3

.add(html)
参数描述
html添加到匹配元素集合的 HTML 片段。

语法 4

.add(jQueryObject)
参数描述
jQueryObject添加到匹配元素集合的已有 jQuery 对象。

语法 5

.add(selector, context)
参数描述
selector字符串值,表示查找供添加到匹配元素集合的元素的选择器表达式。
context选择器开始进行匹配的位置。
来自 http://www.w3school.com.cn/jquery/traversing_add.asp
普通分类: