我在 jquery 中编写了一段代码,将 href 属性分配给变量。这是代码:
$('#reactions' + i).attr('href', 'javascript:comments ('+entry.url+','+i+');');
这应该分配对 javascript 函数注释的调用。现在我想在 jquery 移动按钮上使用该调用,如下所示:
document.write('<a href="#" id="reactions' + i + '" data-role="button" class="ui-btn-right">Reactions</a>');
但是这样做可以让我在 FF 和 Chrome 中获得成功。这是 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+');');
关于javascript - 不应该是变量的 undefined variable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292285/