[英]How can I access current html elements certain property value?
This is my js/jquery code in which I am trying to access the current button that was clicked, with class of delete, and then get the property data-id's value. 这是我的js / jquery代码,我试图在其中访问带有删除类的当前单击的按钮,然后获取属性data-id的值。 When I console.log the string that I hope to have it says undefined?
当我console.log我希望它具有未定义的字符串? Any suggestions on what I am doing wrong?
关于我在做什么错的任何建议吗?
$(".delete").click(function(){
var id = $(this).prop("data-id");
console.log(id);
});
Try 尝试
$('.delete').on('click',function(){
var id= $(this).attr('data-id');
console.log(id);
})
尝试attr()方法。
var id = $(this).attr("data-id");
The shortest would be: 最短的是:
$(".delete").on('click', function(){
var id = $(this).data("id");
console.log(id);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.