So heres my code
html += "<li class='status-"+peeps[i].online_presence+"' onclick='show_connect_message("+peeps[i].uid+");streamPublish("+peeps[i].uid+","+name+");'><a href='#' onclick='show_connect_message("+peeps[i].uid+");streamPublish("+peeps[i].uid+","+name+");return false;'>"+peeps[i].name+"</a></li>";
Basically, when inspecting the element I can see it is outputting a UID and name. Here is the line:
<li class="status-active" onclick="show_connect_message(503141088);streamPublish(503141088,David);"><a href="#" 开发者_如何学JAVAonclick="show_connect_message(503141088);streamPublish(503141088,David);return false;">David</a></li>
So what am I doing wrong. I need the name (David) in double quotes or single quotes because otherwise the console says that it can't find the function referenced.
Warning: Javascript Noob
Thanks for your help!
change
streamPublish("+peeps[i].uid+","+name+")
to
streamPublish("+peeps[i].uid+",\""+name+"\")
the backslash will escape the double quotes and will not break the string
Try this
html += "<li class='status-"+peeps[i].online_presence+"' onclick='show_connect_message("+peeps[i].uid+");streamPublish("+peeps[i].uid+","""+name+""");'><a href='#' onclick='show_connect_message("+peeps[i].uid+");streamPublish("+peeps[i].uid+","""+name+""");return false;'>"+peeps[i].name+"</a></li>";
精彩评论