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.
这可能吗,我的 div 数据属性是:
data-obj="{"__type":"GalleryImgModel","GalleryImageId":49,"GalleryId":0,"PersonId":264}"
以及我根据文档尝试的 jquery(我已经正确定义了项目!)
item.data('obj',{"MoreThanOneImage" : moreThanOneImage});
帮助将非常感谢
您需要先将数据属性字符串转换为对象,然后添加值。尝试类似:
$('#my-element').data($.extend({'new-key':'new-value'}, JSON.parse($('#my-element').data()));
像这样的东西应该可以解决问题。