我收到此错误:
未捕获的错误:NOT_FOUND_ERR:DOM 异常 8
这是我的代码(请提出任何建议以使其更高效/更清洁):
基本上,这是一个将其 ID 添加到名为“关键字”的数组中的按钮:
$('.add').live('click', function() {
if($(this).text() == "+Add") {
console.log("add triggered");
$(this).stop().animate({backgroundColor:'#999d92'}, 300);
$(this).html("-Rem").fadeIn('fast');
keywords.push($(this).attr("id"));
$("#response").append(keywords);
}
else {
$(this).stop().animate({backgroundColor:'#cc6633'}, 300);
$(this).html("+Add").fadeIn('fast');
var index = keywords.indexOf($(this).attr("id"));
keywords.splice(index, index+1);
$("#response").append(keywords);
}
});
我想要发生的是,当“+ADD”被推送时,id 属性被添加到数组中,当 -REM 被推送时,然后从关键字中删除该 id。
任何建议都会有帮助。当我只是将 $(this).attr("id") 附加到响应 div 时,它会正确打印。我还尝试用“String()”函数包围它(也许它是对资源的引用,而不是实际的字符串?)
感谢时间的负责人!