使用jquery更改data-attribute [英] change data-attribute using jquery
本文介绍了使用jquery更改data-attribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改
<div data-300=""></div>
到
<div data-500=""></div>
使用jquery?
我不喜欢我想删除属性并替换它,因为它包含我需要的数据我只需要将'300'更改为'500'。
I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'.
推荐答案
根本不是通用的,但它应该完成这项工作
Not generic at all, but it should do the job
var $target = $('div[data-300]'),
oldData = $target.data('300');
$target.removeAttr('data-300').attr({ 'data-500': oldData });
这篇关于使用jquery更改data-attribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文