嵌入对象的Javascript函数调用不起作用

嵌入对象的Javascript函数调用不起作用,javascript,json,function,Javascript,Json,Function,我正在动态创建一些html,如下所示: html += '<a class="ipadbutton" href="javascript:dashboard_GetProfileStats({&quot;profileid&quot;:&quot;' + profile.id + '&quot;});">Stats</a>'; 但是,该链接在Chrome或Safari中不起作用。你能像这样在HREF中嵌入对象吗? 谢谢。对于javascri

我正在动态创建一些html,如下所示:

html += '<a class="ipadbutton" href="javascript:dashboard_GetProfileStats({&quot;profileid&quot;:&quot;' + profile.id + '&quot;});">Stats</a>';
但是,该链接在Chrome或Safari中不起作用。你能像这样在HREF中嵌入对象吗?
谢谢。

对于javascript来说,"是糟糕的语法。它显示为引号“”,但内部为“”,这导致链接失败

您想要的更像:

html += "<a class=\"ipadbutton\" href=\"javascript:dashboard_GetProfileStats({'profileid': + profile.id});\">Stats</a>';
html+=”;
甚至更好

html += "<a class=\"ipadbutton\" href=\"\" onclick=\"dashboard_GetProfileStats({'profileid': + profile.id});\">Stats</a>';
html+=”;
此外,通常使用事件处理程序处理链接和锚定标记

所以最好的方法是:(通过jquery附加事件)

html+='Stats';
$(函数(){
$('.ipadbutton')。单击(函数(){
dashboard_GetProfileStats({'profileid':+profile.id});
返回false;
});
});

使用
onclick
而不是
href

<a href="#" onclick='javascript:dashboard_GetProfileStats({"profileid":"blablabla"});'> ...
。。。
在onclick中不需要“javascript:…”)
html += '<a class="ipadbutton">Stats</a>';

<script>
  $(function() {
   $('.ipadbutton').click(function() {
     dashboard_GetProfileStats({'profileid': + profile.id});
     return false;
   });
  });
</script>
<a href="#" onclick='javascript:dashboard_GetProfileStats({"profileid":"blablabla"});'> ...