jQuery的.load()函数中断从.load开封后模态()完成 [英] jQuery's .load() function breaks modal from opening after .load() completes

查看:136
本文介绍了jQuery的.load()函数中断从.load开封后模态()完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery的 .load() 方法和加载页面片段的。下面是我目前的code:

I am using jQuery's .load() method and Loading Page Fragments. Below is my current code:

$("#submit").click(function() {
    $("#results").load('/ajax/box/ #box');
});

这code是一个MODA,当 a.ajax模态点击时调用。问题是,当 .load()完成后, a.ajax模态 #box 被装入 #results 工作不......不不开的模式,而是只是打开了新的一页。它看起来像 #box 没有绑定/连接到任何事件处理程序的内容。

This code is in a moda, which is called when a.ajax-modal is clicked. The problem is that when .load() has completed, the a.ajax-modal in #box that was loaded into #results is not working... it doesn't not open the modal but instead just opens a new page. It seems like the contents of #box are not bound/attached to any event handlers.

下面是正在发生的事情的概要:

Here is an outline of what is happening:

  1. 加载页
  2. 点击 a.ajax模态和模态节目
  3. 在模式提交表单,运行。点击()模态
  4. 功能
  5. #results 内容的网页刷新
  6. 点击新 a.ajax模态这是在 #results 加载,但语气显示
  1. Load page
  2. Click on a.ajax-modal and modal shows
  3. Submit form in modal, run .click() function in modal
  4. Content in #results on page refreshes
  5. Click on new a.ajax-modal that was loaded in #results but modal does not show

为什么模态不开放后 .load()完成?

Why is the modal not opening after .load() is complete?

推荐答案

没有事件已被添加到您的元素,因为事件被添加在文档已准备就绪。您需要使用。对()的jQuery方法prevent这一点。

No event has been added to your element because events are added when the document is ready. You need to use .on() method of jQuery to prevent this.

$(function()
    $(document).on('click', 'a.ajax-modal', function() {
       // Your code here.
    });
});

因此​​事件被添加到文件而不是元素本身。

这篇关于jQuery的.load()函数中断从.load开封后模态()完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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