Jquery 使用.getAttribute()从HTML获取属性失败

Jquery 使用.getAttribute()从HTML获取属性失败,jquery,Jquery,我有以下代码: HTML <select disabled class="kurir full-width" data-init-plugin="select2" name="kurir" data-productid="316"> ... </select> 为什么我无法从数据productid获取316?我错过了什么 谢谢。您可以获得如下属性值 this.getAttribute('data-productid') 或 您可以获得如下所示的属性值 this

我有以下代码:

HTML

<select disabled class="kurir full-width" data-init-plugin="select2" name="kurir" data-productid="316">
    ...
</select>
为什么我无法从
数据productid
获取
316
?我错过了什么


谢谢。

您可以获得如下属性值

this.getAttribute('data-productid')


您可以获得如下所示的属性值

this.getAttribute('data-productid')


.getAttribute是我们不能使用的javascript方法,它是jquery对象方法


因此,您可以在下面的语法中使用它-this.getAttribute('data-productid')

.getAttribute是我们不能使用的javascript方法,它是jquery对象方法

因此,您可以在下面的语法中使用它-this.getAttribute('data-productid')

使用

var productid = $(this).data('productid');
使用


使用
.attr('data-productid')使用
.attr('data-productid')
$(this).data('productid')
@显然,KartikeyaKhoslaOr
$(this).data('productid')
@卡提克亚霍斯拉
var productid = $(this).data('productid');