【发布时间】:2014-08-04 07:32:57
【问题描述】:
当单击链接时,我调用ajax 方法,该方法将返回数据为object。在将有我的组名的数据中。我正在尝试empty the group and create a new div,但我收到错误请让我知道你的一些事情:)。
function loadData(data) {
var view = new entryView(data);
var groupName = data.name;
$("#groupName").attr('id').empty();
// error - typeerror $(...).attr(...) is undefined jquery
alert($('#groupName').attr('id'));
}
entryView(data) {
this.name = this.data.name
}
我不断收到TypeError: $(...).attr(...) is undefined。有人可以告诉我问题是什么吗?我的 jQuery 在下面。谢谢。
【问题讨论】:
-
你用的是什么浏览器?
-
您尝试在字符串上调用
empty()方法,这就是您收到错误的原因 -
这一行是否运行 alert($('#groupName').attr('id'));如果你放在错误行之前?以及它在警报中显示的内容?
-
试试这个怎么样:$("#"+groupName).attr('id','');
-
或 $("#"+data.name).empty()