
- jQuery 教程
- jQuery - 首頁
- jQuery - 路線圖
- jQuery - 概述
- jQuery - 基礎
- jQuery - 語法
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 屬性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 新增元素
- jQuery - 刪除元素
- jQuery - 替換元素
- jQuery CSS 操作
- jQuery - CSS 類
- jQuery - 尺寸
- jQuery - CSS 屬性
- jQuery 效果
- jQuery - 效果
- jQuery - 動畫
- jQuery - 鏈式操作
- jQuery - 回撥函式
- jQuery 遍歷
- jQuery - 遍歷
- jQuery - 遍歷祖先元素
- jQuery - 遍歷後代元素
- jQuery UI
- jQuery - 互動
- jQuery - 小部件
- jQuery - 主題
- jQuery 參考
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍歷
- jQuery - 雜項
- jQuery - 屬性
- jQuery - 工具函式
- jQuery 外掛
- jQuery - 外掛
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用資源
- jQuery - 常見問題解答
- jQuery - 快速指南
- jQuery - 有用資源
- jQuery - 討論
jQuery not() 方法
jQuery 中的not()方法用於從匹配元素集中過濾掉元素。換句話說,它從匹配元素集中刪除與指定選擇器匹配的元素。
語法
以下是 jQuery 中 not() 方法的語法:
$(selector).not(criteria,function(index))
引數
此方法接受以下引數:
- criteria: 一個選擇器表示式、元素或 jQuery 物件,指示要移除的元素。
- function(index): 可選的回撥函式,用於對匹配集中每個元素執行,其中index表示當前元素的索引。
示例 1
在下面的示例中,我們使用 not() 方法來選擇所有沒有類名“demo”的元素:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").not(".demo").css("border", "2px solid green") }) }); </script> </head> <body> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p class="demo">Paragraph element (with class demo).</p> <button>Click</button> </body> </html>
當我們執行上述程式時,所有沒有類名“demo”的元素都將以實心綠色邊框突出顯示。
示例 2
在這個示例中,我們返回所有沒有類“demo”和 id“dummy”的元素:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").not(".demo, .dummy").css("border", "2px solid green") }) }); </script> </head> <body> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p>Paragraph element.</p> <p class="dummy">Paragraph element (with class dummy).</p> <button>Click</button> </body> </html>
當我們執行上述程式時,所有沒有類名“demo”和“dummy”的元素都將以實心綠色邊框突出顯示。
示例 3
這裡,我們選擇所有沒有類“demo”和 id“dummy”的<p>元素:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").not($("p.demo, p.dummy")).css("border", "2px solid green") }) }); </script> </head> <body> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p class="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p>Paragraph element.</p> <p class="dummy">Paragraph element (with class dummy).</p> <button>Click</button> </body> </html>
執行上述程式後,所有沒有類名“demo”和“dummy”的<p>元素都將以實心綠色邊框突出顯示。
示例 4
這裡,我們返回所有沒有 id“demo”的元素,使用 DOM 元素:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").not(document.getElementById("demo")).css("border", "2px solid green") }) }); </script> </head> <body> <p id="demo">Paragraph element (with class demo).</p> <p>Paragraph element.</p> <p>Paragraph element.</p> <p>Paragraph element.</p> <button>Click</button> </body> </html>
執行上述程式後,所有沒有類名“demo”的元素都將以實心綠色邊框突出顯示。
jquery_ref_traversing.htm
廣告