本文介绍了jQuery元素[attribute = something] vs element.class性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想知道哪种方式会更快,选择元素: $('element [href =# my_link]'); 或: code> $('element.my_class'); 我不喜欢在写代码时重复自己,所以我更喜欢写第一种方式因为我可以像下面这样添加信息: < a href =#delete_1> Delete< ; / a> $('a [href ^ =#delete]'); 然后拆分它,以便我获得所有需要的信息,或任何动作可能是。 (我想我可以将其重写为class =deletehref =#1)解决方案 按类选择元素需要: 453 ms 按元素选择元素+搜索需要578 ms 请检查这个伟大的网页以进行更多测试: Jquery性能 I am wondering which way would end up being faster, selecting elements by:$('element[href=#my_link]');or:$('element.my_class');I don't like repeating myself when I write code, so I prefer to write it the first way for the most part because then I can add information to it like:<a href="#delete_1">Delete</a>$('a[href^=#delete]');and then split it up so that I have all of the information that I need once it is clicked, or whatever the action may be. Am I sacrificing overall performance because of this?(I guess I could rewrite it as class="delete" href="#1") 解决方案 selecting an Element by class needs :453 msselecting an Element by element + search needs 578 ms both in FireFox.Checkout this great Webpage for more tests:Jquery Performance 这篇关于jQuery元素[attribute = something] vs element.class性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 20:47