javascript - 不应该是变量的 undefined variable 错误

标签 javascript jquery variables

我在 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_whatentry.url 的值。

我只是不明白为什么会出现这个错误,据我所知,一切都应该有效。 我知道有些问题与我的相似,但我无法找到答案。如果你想查看完整的源代码,那就是 here .

最佳答案

用引号将entry.url括起来:

    $('#reactions' + i).attr('href', 'javascript:comments ("'+entry.url+'",'+i+');');

关于javascript - 不应该是变量的 undefined variable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292285/

相关文章:

javascript - 为什么 javascript 会增加我的号码?

javascript - 从 dataurl 获取图像的高度和宽度

jquery - 使用 jQuery 在翻转时显示完整版本的缩略图?

jquery - 两个表行的高度始终相同

javascript - 在 package.json 中设置包版本

jquery - 当我点击打开它的链接时,为什么这个 div 不会关闭?

C# 通过变量引用方法?

php/mysql变量

php - 如何将 php session 变量从页面传输到页面内的 iframe

javascript - 与 async.series 不同,async.applyEachSeries 无法引用 'this'