如何用JavaScript获取标签元素的data-*属性值?
- 内容介绍
- 文章标签
- 相关推荐
本文共计623个文字,预计阅读时间需要3分钟。
目录+ 方式一:dataset+ 方式二:getAttribute/setAttribute/removeAttribute+ 方式三:jQuery.attr+ 方式四:jQuery.data+ 前言:标签上存在两个属性 data-id 和 data-user-name,需要通过js去获取。
本文共计623个文字,预计阅读时间需要3分钟。
目录+ 方式一:dataset+ 方式二:getAttribute/setAttribute/removeAttribute+ 方式三:jQuery.attr+ 方式四:jQuery.data+ 前言:标签上存在两个属性 data-id 和 data-user-name,需要通过js去获取。

