我用$(".button").on("click", function(){ });

单击容器上的一个按钮,然后进行ajax调用,内容

I even tried

$(".button").live("click", function(){ });

or

$(".button").click(function(){ });

How can I make it work?

EDIT : my html:

<div class="container">
   <ul>
       <li>item1</li>
       <li>item2</li>
       <li>item3</li>
   </ul>
   <input type="button" value="reload" class="button" />
</div>

推荐答案

应该这样做.

$('body').on('click', '.button', function (){
        alert('click!');
    });

If you have a container that doesn't change during the ajax request, this is more performant:

$('.container').on('click', '.button', function (){
        alert('click!');
    });

Always bind the delegate event to the closest static element that will contain the dynamic elements.

Jquery相关问答推荐

try 使用jQuery AJAX将参数传递给http Post方法时出现未知错误

jQuery:如何动态检测窗口宽度?

jQuery中的多个 Select 器链接?

在 jQuery 中,我想删除 div 中的所有 HTML

使用 jQuery Validate 确认密码

jQuery/JavaScript 碰撞检测

如何禁用在div内单击

禁用 Android 网页中输入焦点的zoom

jQuery中追加的相反

Jquery,清除/清空 tbody 元素的所有内容?

为什么找不到我的 json 文件?

如何阻止 Chrome 进入调试模式?

您如何处理 jQuery 中的表单更改?

Jquery Ajax 错误处理忽略中止

如何使用 JQuery 创建一个新的 img 标签,其中包含来自 JavaScript 对象的 src 和 id?

jQuery:如何找到父母的特定子元素?

在jQuery中获取CSS规则的百分比值

$.getJSON 在 IE8 中返回缓存数据

添加到数组 jQuery

jQuery append() 与 appendChild()