【发布时间】:2013-04-23 19:16:50
【问题描述】:
我正在努力寻找正确的语法来通过带有附加功能的 javascript/jquery 添加按钮。
现在我正在尝试:
list.append("<button onclick='getFeed('http://open.live.bbc.co.uk/weather/feeds/en/PA2/3dayforecast.rss, showFeedResults')'>ButtonTest</button>");
但它会返回:
<button onclick="getFeed(" http:="" open.live.bbc.co.uk="" weather="" feeds="" en="" pa2="" 3dayforecast.rss,="" showfeedresults')'="">ButtonTest</button>
本质上,我希望能够创造
<button onclick="getFeed('http://open.live.bbc.co.uk/weather/feeds/en/B1/3dayforecast.rss', showFeedResults)" class="ui-btn-hidden">
在 javascript 中,但无法弄清楚如何..`
而且我似乎在创建同时使用单引号和双引号的 html 元素时遇到了麻烦。
任何建议将不胜感激。
【问题讨论】:
-
以下答案是更好的解决方案,但您的问题可以通过使用转义引号来解决,例如 var text = "aaa\"bb";
标签: javascript jquery button