jQuery 双事件在发布/获取后触发

发布于 2024-09-09 06:43:12 字数 532 浏览 0 评论 0原文

好吧,我和其他人绞尽脑汁想弄清楚为什么在 IE 和最新版本的 FF 中会发生这种情况。它适用于镀铬。我只是一名新手开发人员,最近开始使用 jquery。所以我什至不知道我是否正确地处理了这个问题。

它在很大程度上是一种基本形式。 jquery ajax post() 然后 get() 来更新页面。一旦从 get 加载页面,右侧导航/侧边栏可折叠标题就会双火,操作窗格中的操作链接也会双火。我尝试使用bind()、live() 和delegate() 绑定点击事件。它最初与绑定一起工作,但我必须在 ajax 调用后重新绑定所有点击事件,我正在尝试找到解决该问题的方法。

我已经设置了我在这里构建的应用程序的静态版本:

http://ishiftdelete。 com/pw_mkvi/ajax_wtf.htm

进行测试:单击右侧导航/侧边栏中操作页面内的编辑页面链接。这将打开一个带有表单和提交按钮的模型对话框。

ok i've wracked my brain and others to figure out why this is happening in IE and latest version of FF. It works in chrome. i am but a novice developer and recently started using jquery. so i dont even know if i'm going about this correctly.

its a basic form for the most part. jquery ajax post() then get() to update the page. once the page is loaded from get, the right hand nav/sidebar collapsible headings double fire and so do the action links in the action pane. i've tried binding the click event with bind(), live(), and delegate(). it worked originally with bind but i had to rebind all my click events after the ajax call and i am trying to find a way around that.

i've set up a static version of the app that i'm building here:

http://ishiftdelete.com/pw_mkvi/ajax_wtf.htm

to test: click on the Edit Page link inside the actions page in the right-hand nav/sidebar. this will open a model dialog with a form and submit button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

困倦 2024-09-16 06:43:12

好吧,我的一个朋友明白了这一点。显然脚本被加载了两次。

坏:

$.get(gurl, function (data) {
    var $response = $('<div />').html(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

好:

$.get(gurl, function (data) {
    var $response = $(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

Ok so a friend of mine figured this out. Apparently scripts were being loaded twice.

BAD:

$.get(gurl, function (data) {
    var $response = $('<div />').html(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});

GOOD:

$.get(gurl, function (data) {
    var $response = $(data);
$('#mydiv').html($response.find('#mydiv').html()); //form
});
漫漫岁月 2024-09-16 06:43:12

我知道您已经解决了这个问题,但对于未来的查找者,您可以在

周围添加一个包装器,如下所示:

<div id="myDivParent">
  <div id="myDiv"></div>
</div>

然后您可以使用 .load() 和您要查找的元素,如下所示:

$("#myDivParent").load(gurl + " #myDiv");

就是这样,如果您通过作为 url 选择器 的参数,它只会从响应中获取该元素:)

I know you've already solved this, but for future finders, you can add a wrapper around your <div> like this:

<div id="myDivParent">
  <div id="myDiv"></div>
</div>

Then you can simplify your situation with .load() and the element you're looking for, like this:

$("#myDivParent").load(gurl + " #myDiv");

That's it, if you pass the argument as url selector it'll get only that element from the response :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文