jQuery的形式不工作的ajaxed内容时,一部分 [英] jQuery form not working when part of ajaxed content

查看:103
本文介绍了jQuery的形式不工作的ajaxed内容时,一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了​​一个面的搜索中,表单数据序列化,并用来确定内容拉使用负载()。我有两个主要部分,侧边栏( .sidebar ),并将结果区域(。结果),所有包裹在一个包装( .wrap )股利。

I'm setting up a faceted search where form data is serialized and used to determine the content to pull in using load(). I have two main sections, the sidebar (.sidebar) and the results area (.results), all wrapped in a wrapper (.wrap) div.

var mainContent = .results

$('#facets').change(function(e){
    mainContent.load('?' + formData + ' .results');
    e.preventDefault();
});

当我执行这种方式,形式不断实现预期的功能(负载结果异步的变化()。)

When I do execute it this way, the form continues to function as intended (loads results asynchronously on change().)

...但是很重要的形式,也可以加载以及,因为面是动态填充的搜索结果。

...but it's important that the form also be loaded as well, since the facets are dynamically populated by the search results.

当我修改日程地址搜索Maincontent 变量整个包装DIV ...

When I change the mainContent variable to the whole wrapper div...

var mainContent = .wrap

$('#facets').change(function(e){
    mainContent.load('?' + formData + ' .wrap');
    e.preventDefault();
});

..表单提交的关于改革的第一次,但会停止reacticting后,它通过拉高到DOM AJAX

我在想什么?

推荐答案

使用 授事件 ,因为该元素DOM加载后通过AJAX加载的:

Use delegated event, as the element is loaded via ajax after DOM load:

$(document).on('change','#facets',function(e){
    mainContent.load('?' + formData + ' .wrap');
    e.preventDefault();
});

这篇关于jQuery的形式不工作的ajaxed内容时,一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆