[英]jQuery performance in terms of getting attribute value
在獲取元素的屬性值時,下面這三個之間的性能有何不同?
a)attr()函數
$('div').click(function() {
var div_id = $(this).attr('id');
// rest of the logic
});
b)事件對象的目標屬性
$('div').click(function(e) {
var div_id = e.target.id;
// rest of the logic
});
c)純JS方法
$('div').click(function() {
var div_id = this.id;
// rest of the logic
});
無疑,選項c與其他選項相比會更好:
$('div').click(function() {
var div_id = this.id;
// rest of the logic
});
因為這在瀏覽器本身中可用,並且您沒有像其他兩個庫那樣使用任何外部庫的其他方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.