问题描述
我正在div内加载一个php页面,该页面需要一个已发布的变量来显示正确的内容.它可以使用以下方式工作:
i am loading a php page inside a div that takes a posted variable to display the proper content. it works using this:
$(".mainArea").load("page.php", {'folder': 'a'}).fadeIn();
//passes vars, but all my jquery event handlers no longer work
问题在于,我动态加载了此内容后-我无法使事件处理程序正常工作.所以我认为解决方案是这样的:
the problem is that after i dynamically load this content - i cant get my event handlers to work. so i thought the solution would be this:
$(".mainArea").on("load", "page.php", {'folder': 'a'}).fadeIn();
// all event handlers still work - but the variables do not get posted...
关于如何将两者结合或让后者实际传递变量的任何想法?
any ideas on how i can combine these two or get the later to actually pass variables?
推荐答案
-
.load
从指定的URL从服务器加载数据并将结果放置在服务器上.指定元素中的内容..load
loads data from the server from the specified URL and places the resulting content in the specified element.load
event 发生在元素及其子元素已完全加载.此事件仅适用于某些类型的元素.The
load
event occurs when an element and its sub-elements have been completely loaded. This event is only available on certain types of elements.基本上,它们执行两项完全不同的操作(但是它们在jQuery中确实具有相同的函数名,因此很容易混淆).
Basically, they do two completely different things (but they do have the same function name in jQuery so they are easily confused).
关于在加载新内容时事件处理程序未绑定的问题,需要使用
on
:As for your problem of event handlers being un-bound when you load new content in, you need to use event delegation using
on
:$("container_selector").on("event", "child-element-selector", function () {...});
这篇关于.load与.on("load")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!