[英]Alert shows [object Object]?
I'm trying to alert an id but it shows [object Object]
. 我正在尝试提醒id,但它显示
[object Object]
。 How to get an ID? 如何获得身份证?
$('.x3').click(function() {
var id = $(this.id);
alert(id);
});
$(this)
is an DOM element
. $(this)
是一个DOM element
。 Try to access the attr
property of the element. 尝试访问元素的
attr
属性。
$('.x3').click(function(){
var id = $(this).attr("id");
alert(id);
);
var id = $(this.id);
This statement simply returns a jQuery wrapper object (with length
0 if there is no matching element exists on DOM). 该语句只返回一个jQuery包装器对象(如果DOM上没有匹配的元素,则
length
0)。
Stringifying it to show it on alert
will print [object Object]
. 对其进行字符串化以在
alert
时显示它将打印[object Object]
。 You rather meant to use 你宁愿使用
var id = this.id; // or var id = $(this).attr('id')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.