通过javascript / jquery添加带onclick功能的按钮

前端之家收集整理的这篇文章主要介绍了通过javascript / jquery添加带onclick功能的按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在努力找到通过附加功能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中,但无法弄清楚如何……

而且我似乎无法绕过创建使用单个和双重qoutation标记的html元素.

任何建议将不胜感激.

解决方法

http://api.jquery.com/on/

list.append("<button>ButtonTest</button>");

list.on("click","button",function(){
    getFeed('http://open.live.bbc.co.uk/weather/Feeds/en/PA2/3dayforecast.RSS,showFeedResults');
});

对于动态生成的元素,使用如上所述的.on()方法.

猜你在找的jQuery相关文章