如何触发事件处理程序后,AJAX的内容在JQuery中已加载 [英] How to fire event handlers after AJAX content has loaded in JQuery
问题描述
我试图使用AJAX请求加载某些信息到使用JQuery表。我可以很容易地加载的内容,但我有添加事件处理的问题,以应用样式上加载的内容。
我申请一个条带化部件表。然而,当我的AJAX请求回来,我的信息附加到它没有风格应用的表身。
jQuery的教程中提到使用load事件来处理这个问题,但我不能让它的工作。
任何帮助将是AP preciated。
$(文件)。就绪(函数(){ $(#cowTable)的tablesorter()。 addTableStriping(); }); 功能addTableStriping(){ $(#cowTable)。tablesorter的({ //分拆找 小部件:['斑马线'] }); }; $(函数(){ $(#loadCowsButton)。点击(函数(){ $。员额(loadCows.php,scottm功能(XML){ $(#cowTable TBODY)追加(XML); }); }); });
我找到了一个解决方案。您需要在更新后触发applyWidgets。感谢您从大家的帮助,我也不会发现这一点,没有你们的帮助。
$(函数(){ $(#loadCowsButton)。点击(函数(){ $。员额(loadCows.php,scottm功能(XML){ $(#cowTable)追加(XML)。 $(#cowTable)触发(更新)。 $(#cowTable)。触发(applyWidgets) }); }); });
I'm trying to use an AJAX request to load some information into a table using JQuery. I can load the content easily but I am having problems adding event handlers to apply style on the loaded content.
I am applying a striping widget to the table. However when my AJAX request comes back and my information is appended to the table body it does not have the style applied.
The JQuery tutorial mentions using the load event to handle this, but I can't get it to work.
Any help would be appreciated.
$(document).ready(function(){ $("#cowTable").tablesorter(); addTableStriping(); }); function addTableStriping(){ $("#cowTable").tablesorter({ // striping looking widgets: ['zebra'] }); }; $(function(){ $("#loadCowsButton").click(function(){ $.post("loadCows.php", "scottm", function(xml) { $("#cowTable tbody").append(xml); }); }); });
I've found a solution for this. You need to trigger "applyWidgets" after updating. Thanks for all the help from everyone, I wouldn't have found this out without your help.
$(function(){ $("#loadCowsButton").click(function(){ $.post("loadCows.php", "scottm", function(xml) { $("#cowTable").append(xml); $("#cowTable").trigger("update"); $("#cowTable").trigger("applyWidgets") }); }); });
这篇关于如何触发事件处理程序后,AJAX的内容在JQuery中已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!