Jquery 使用.getAttribute()从HTML获取属性失败
我有以下代码: HTMLJquery 使用.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
<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')显然,code>或$(this).data('productid')
@显然,KartikeyaKhoslaOr$(this).data('productid')
@卡提克亚霍斯拉
var productid = $(this).data('productid');