Mootools:如何让Behavior与ajax加载的元素一起工作?
我正在使用 Mootools Behavior - https://github.com/anutron/behavior。它工作正常,但 ajax 加载的元素的行为不适用。
这是我的代码:
var request = new Request.HTML({
url: get_url(),
append: $(api.get('append')),
evalScripts: true,
onSuccess: function(){
window.behavior.apply(document.body);
}
});
它不起作用。
(window.behavior 是主要的Behavior 实例)
提前致谢。
UPD。这是我自己的静态加载问题。上面的代码应该可以工作。
I'm using Mootools Behavior - https://github.com/anutron/behavior. It works fine but behavior of elements that are ajax-loaded doesn't apply.
Here's my code:
var request = new Request.HTML({
url: get_url(),
append: $(api.get('append')),
evalScripts: true,
onSuccess: function(){
window.behavior.apply(document.body);
}
});
And it doesn't work.
(window.behavior is the main Behavior instance)
Thank in advance.
UPD. That was my own problem with static loading. The code above should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您应该尝试在Behavior.apply()方法上设置第二个可选参数。
在成功回调函数中尝试
window.behavior.apply(document.body, true)
。如果第二个参数“force”设置为 true,则已处理过的元素将被再次处理。这可能是您的问题,如果不是,请回来查看并让我们立即处理。Maybe you should try to set the second, optional parameter on the Behavior.apply()-method.
Try
window.behavior.apply(document.body, true)
in your success-callback function. Elements which already have been processed will be processed again, if the second parameter "force" is set to true. That could be your problem, if not, check back and let us now please.不要将该行为重新应用到整个文档,而是仅将其重新应用到新内容。我经常使用这种模式并取得成功。
Instead of re-applying the behavior to the entire document, re-apply it to the new content only. I use this pattern frequently with success.