JQuery live 或与 .change() 类似的东西?

发布于 2024-08-03 02:50:28 字数 222 浏览 4 评论 0原文

我想这样做: http://docs.jquery.com/Events/live#typefn< /a>

只有 .live() 不支持更改事件 - 有解决方法吗?

需要将函数绑定到某些动态 DOM 元素,但直到发生更改。

I want to do this: http://docs.jquery.com/Events/live#typefn

Only .live() doesn't support the change event- any ideas for work arounds?

Need to bind a function to some on-the-fly DOM elements, but not until change.

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

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

发布评论

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

评论(5

手心的海 2024-08-10 02:50:28

注意:jQuery 1.4 现在支持所有正常事件的 live 功能。直到最近它才支持 IE8,但我相信 jQuery 1.4.2 已经解决了这个问题。请参阅此已解决的 jQuery 票证:IE8 在使用 LIVE 时不支持更改事件

Note: jQuery 1.4 now supports the live function for all normal events. It didn't work with IE8 until recently, but I believe this is fixed with jQuery 1.4.2. See this resolved jQuery ticket: IE8 DOES NOT SUPPORT THE CHANGE EVENT WHILE USING LIVE

夜司空 2024-08-10 02:50:28

LiveQuery 插件 支持所有事件。

LiveQuery plugin supports all events.

娇俏 2024-08-10 02:50:28

哦,那还不错,我只是将它包装在一个实时点击事件中,它工作得很好。


$("#foo").live("click", function(){
  $('.fu').change(function(){
    blah blah blah
  });
});

Oh that wasn't so bad, i just wrapped it in a live on click event and it worked just fine.


$("#foo").live("click", function(){
  $('.fu').change(function(){
    blah blah blah
  });
});

活雷疯 2024-08-10 02:50:28

好吧,在 Funka 对我第一次尝试回答自己的问题发表评论之后,我现在有了这个:


$('.foo').change(function test(){
  $(fu).prependTo("#some-div").bind("change", test)
  $(this).unbind("change",test)
};

这将在创建时将函数绑定到每个元素,并将其与之前创建的元素解除绑定。这解决了我在用户界面方面的问题,但我是新手,所以如果我再次错过一些东西,我真的很愿意学习! ;)

Ok, after Funka's comments on my first attempt at answering my own question, I now have this:


$('.foo').change(function test(){
  $(fu).prependTo("#some-div").bind("change", test)
  $(this).unbind("change",test)
};

Which will bind the function to each element as it is created, and unbind it from the one created before it. This solves my problem UI-wise, but I'm obvs novice so am really open to learning if I am missing something again! ;)

自由范儿 2024-08-10 02:50:28

在 jQuery 1.3 中出现 .live() 之前,我使用 Arial Flesler 的“listen”插件取得了巨大成功。

http://flesler.blogspot.com/search/label/jQuery.Listen

我相信您应该能够使用此插件在更改事件上执行此操作。

Before there was .live() in jQuery 1.3, I had great success with Arial Flesler's "listen" plugin.

http://flesler.blogspot.com/search/label/jQuery.Listen

I believe you should be able to do this on the change event with this plugin.

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