簡體   English   中英

向包含類的所有img添加數據操作

[英]Add data-action to all img that contain a class

我正在使用此插件: https : //github.com/fat/zoom.js/

我想選擇所有具有img-responsive img類的img-responsive ,並將data-action="zoom"到該元素。 使用jQuery是否可能? 性能會真的很差嗎?

使用jQuery.data( key, value )方法

$('img.img-responsive').data('action','zoom');

或使用jQuery.attr( attributeName, value )

$('img.img-responsive').attr('data-action','zoom');

只需使用

$('img[class="img-responsive"]').attr('data-action', 'zoom');

性能應該很好:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM