未定义的变量错误,不应该是一个变量
我已经在jQuery中做了一段代码,它将一个href属性赋值给一个变量。这里的代码:未定义的变量错误,不应该是一个变量
$('#reactions' + i).attr('href', 'javascript:comments ('+entry.url+','+i+');');
这应该分配一个调用javascript函数注释。现在我想使用电话上的jQuery Mobile的按钮,像这样:
document.write('<a href="#" id="reactions' + i + '" data-role="button" class="ui-btn-right">Reactions</a>');
但这样做给了我在FF和铬。这是从FF误差±
Uncaught exception: ReferenceError: Undefined variable: i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what Error thrown at line 1, column 0 in javascript:comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);: comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);
在此,i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what
是entry.url
值。
我只是不明白为什么会出现这个错误,据我所知,一切都应该工作。 我知道有类似于我的问题,但我无法弄清楚答案。如果你想看到整个来源,它是here。
环绕entry.url引号:
$('#reactions' + i).attr('href', 'javascript:comments ("'+entry.url+'",'+i+');');
来解决该问题的最好办法是做了“jQuery的方式”。而不是增加执行JavaScript的一个href属性,添加一个click事件:
$('#reactions' + i).click(function() {
comments(entry.url, i);
});
同样不使用document.write()
但元素添加到使用jQuery功能的文档。