Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您好,我正在尝试将 jQuery 数据属性添加到我正在创建的用户脚本中。
$('#divID .classsample').data('image');
您可以按以下方式进行:
var div = $("#divID .classsample"); jQuery.data(div, "image", "url"); alert(jQuery.data(div, "image"));
实际上并不了解您需要什么,但尝试url为您的属性设置一些值(例如)data:
url
data
$('#divID .classsample').data('image' , url);
如果“到数据属性”意味着“设置数据属性”