jquery on()没有处理ajax加载的元素

时间:2012-04-19 07:37:44

标签: jquery ajax

我在页面上通过ajax加载了html表。现在我想通过jquery操作表。所以我使用on()函数,问题是我需要将一个事件作为参数传递给它,以使它做一些事情

例如:

 $(document).on("click", "table#cal", function(event){
    alert("loaded");
   });

有没有其他方法可以在加载表格后立即执行类似数据等的操作而不必“点击”它?

1 个答案:

答案 0 :(得分:4)

你不能在AJAX调用的.success()回调中做到吗?

$.ajax({
    // ajax settings
})
.success(function (m) {
    // get the table data
    // build the table
    // place the table on your DOM
    // get yourself a cup of coffee
    // do backflips
    // feed the dog
    // ...
    // manipulate the table
});
相关问题