I have the following problem with this code:

<button id="delete">Remove items</button>

$("#delete").button({
     icons: {
             primary: 'ui-icon-trash'
     }
}).click(function() {
     alert("Clicked");
});

If I click this button, the alert show up two times. It's not only with this specific button but with every single button I create.

What am I doing wrong?

推荐答案

Your current code works, you can try it here: http://jsfiddle.net/s4UyH/

在示例之外有一些东西正在触发另一个.click(),请判断正在also触发该元素上的click事件的其他处理程序.

Jquery相关问答推荐

将 jquery 元素转换为 html 元素

Jquery each - 停止循环并返回对象

递归循环遍历对象(树)

jQuery 与 javascript?

如何使用 jQuery 的 getJSON() 方法传递请求标头?

使用 jQuery 和 HTML 导出为 CSV

如何使用 jQuery 搜索 JSON 树

jQuery从下拉列表中删除一个选项,给定选项的文本/值

如何判断是否有任何 JavaScript 事件侦听器/处理程序附加到元素/文档?

组合数组时无法读取未定义的属性推送

如何同时使用 requireJS 和 jQuery?

如何重新启用 event.preventDefault?

jquery获取帖子操作网址

在 jquery 中启用/禁用下拉框

将打开/关闭图标添加到 Twitter Bootstrap 可折叠项(手风琴)

jquery分别绑定双击和单击

如何在纯 JavaScript 中模拟鼠标悬停以激活 CSS:悬停?

如何在调用 Ajax 等异步调用时让代码等待

IE8 和 JQuery 的 trim()

使用javascript将HTML页面中的div下载为pdf