我很感興趣哪種方法更快::not
選擇器或not()
方法。 例如,在這樣的查詢:jQuery:不是選擇器
$(this).find(':input').not(':input[type=button], :input[type=submit], :input[type=reset]').each(function() { ... });
謝謝
我很感興趣哪種方法更快::not
選擇器或not()
方法。 例如,在這樣的查詢:jQuery:不是選擇器
$(this).find(':input').not(':input[type=button], :input[type=submit], :input[type=reset]').each(function() { ... });
謝謝
見http://jsperf.com/jquery-css3-not-vs-not
:不平均爲大約快一倍。
正如kolink說:not
比較快,因爲你不加入一個函數調用,您可以在jsperf
比較速度,例如:in this test
試試這個請:
良好讀取:jQuery selector question (how to select all input fields on a form EXCEPT buttons and checkbox)
http://api.jquery.com/not-selector/
這將有助於你的事業:)
代碼
$(this).find(':input:not(:button):not(:submit):not(:reset)').each(function() { ... });
+1 ....喜歡......':)' – thecodeparadox 2012-08-07 03:38:25
@thecodeparadox兄弟,Howz生活! ':)'謝謝你! – 2012-08-07 03:39:31
野生的猜測是,他們使用相同的機制,這樣就使得':not'稍快,由於沒有打電話給一個全新的功能。 – 2012-08-07 03:23:53
我同意Kolink。我想你會看到不同之處,如果你使用Chrome的分析工具。 – Pascal 2012-08-07 03:25:53