【发布时间】:2013-10-12 22:52:28
【问题描述】:
我想将元素的标签作为字符串并在 jquery 中提醒该字符串。我在下面写了代码,但我得到了 [object][Object] 值。我也尝试了 html() 和 text() 但它没有用。
function seatObject(id, label, status, token){
this.id = id;
this.label = label;
this.status = status;
this.token = token;
}
for (var x = 0; x < 5; x++) {
var temp = new seatObject("#" + x, "label" + x, "available", "");
seats[x] = temp;
$("#" + x).click(function () {
currentSeat = $(this).attr("id");
var label = $("label[for="+$(this).attr('id')+"]");
alert(label);
});
}
这也是我的标签;
<rect style="fill: #888888;" id="0" width="35.823246" height="35.823246" x="299.87155" y="65.999405" class="seatObj" label="A24"></rect>
【问题讨论】:
-
var label = $("label");警报(标签。文本());这对我有用fiddle.jshell.net/kU7Pb
-
我试过了,但我得到了 [object][Object] 值
-
你的
seatObject函数是做什么的?可以发一下代码吗? -
函数座位对象(id,标签,状态,令牌){ this.id = id; this.label = 标签; this.status = 状态; this.token = 令牌; }
标签: jquery asp.net-mvc asp.net-mvc-4