$(* [attr])和$([attr])之间的差异(difference between $(*[attr]) and $([attr]))
我只想知道以下$(*[attr])和$([attr])哪一个更好。 为什么?
因为两者都是一样的。
$('[onclick]').each(function(i,elem){ console.log(elem.onclick); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div onclick="asd()"></div> <div onclick="def()"></div> <div id="dv1"></div> <div id="dv2"></div>$('*[onclick]').each(function(i,elem){ console.log(elem.onclick); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div onclick="asd()"></div> <div onclick="def()"></div> <div id="dv1"></div> <div id="dv2"></div>还有浏览器支持呢。
如果我问复制品,请道歉。
I just want to know which one is preferable in the following $(*[attr]) and $([attr]). Why?
Because both are doing same.
$('[onclick]').each(function(i,elem){ console.log(elem.onclick); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div onclick="asd()"></div> <div onclick="def()"></div> <div id="dv1"></div> <div id="dv2"></div>$('*[onclick]').each(function(i,elem){ console.log(elem.onclick); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div onclick="asd()"></div> <div onclick="def()"></div> <div id="dv1"></div> <div id="dv2"></div>And also what about the browser support.
Apologize if i asked the duplicate one.
最满意答案
我认为两者在行为层面上是相同的。
正如@satpal在评论中所说。
我试过jsPref,它说$('*[onclick]')是最快的。
谢谢@satpal
I think Both are same in behavioral level.
As @satpal said in comment.
I tried in jsPref, It says $('*[onclick]') is the fastest.
Thanks @satpal
更多推荐
发布评论