jQuery API .not()

来源:互联网 发布:在淘宝上买电脑靠谱吗 编辑:程序博客网 时间:2024/05/22 04:26

.not()

描述: 从匹配的元素集合中移除指定的元素。

  • .not( selector )

    • selector
      类型: Selector
      一个用于匹配元素的选择器字符串。
  • .not( elements )

    • elements
      类型: Elements
      要从匹配元素集合中移除的一个或多个DOM元素。
  • .not( function(index) )

    • function(index)
      类型: Function()
      一个函数用作测试集合中的每个元素。this 是当前DOM元素。
  • .not( jQuery object )

    • jQuery object
      类型: PlainObject
      现有匹配当前元素集合的jQuery对象。
如果提供的jQuery对象代表了一组DOM元素,.not()方法构建一个新的匹配元素的jQuery对象,用于存放筛选后的元素。所提供的选择器是对每个元素进行测试;如果元素不匹配的选择将包括在结果中

例子:

Example: 为不是绿色或蓝色的 div 添加边框。

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script src="jquery-1.10.2.js"></script><style>div { width:50px; height:50px; margin:10px; float:left; background:yellow; border:2px solid white; }.green { background:#8f8; }.gray { background:#ccc; }#blueone { background:#99f; }</style></head><body> <div></div><div id="blueone"></div><div></div><div class="green"></div> <div class="green"></div><div class="gray"></div><div></div> <script> $("div").not(".green,#blueone").css("border-color","red"); </script> </body></html>
效果图:

Example: 从段落集合中移除 ID 是 "selected" 的元素。

1
$("p").not( $("#selected")[0] )

Example: 从段落集合中移除 ID 是 "selected" 的元素。

1
$("p").not("#selected")

Example: 从段落集合中移除满足 "div p.selected" 的元素。

1
$("p").not($("div p.selected"))

0 0
原创粉丝点击