English 中文(简体)
无法从JQuery.live()迁至JQuery.on()
原标题:Unable to move from JQuery.live() to JQuery.on()

我正在用美元将约html装入Jquery-dialog-popup。

在新插入的html中点击一个环节后,应当启动一些功能。

这与(a)但NOT与(b)一起工作。

这项工作:

$(".remove").live("click", function () {
  // enter ok
}

这并不是:

$("div").on("click", ".remove", function () {
// or $("#delete").on("click", ".remove", function () {
// or $(".remove").on("click", function () {

      // never enters...
});  

html:

<div id="delete">
  <a class="remove" href="#">link</a>
</div>

如果我直接从我的主机上叫它,而不首先用美元将内容装入方言-窗口,则“()”功能工程。

最佳回答

To pre-bind events for dynamic content, they have to be bound to a pre-existing element.

因此,如果<代码><div id=“delete”>是动态内容的一部分,那么你就不必使用它来约束这一活动。 然而,你可以把动态成分装入集装箱。

因此,如果由此产生的超文本为:

<div id="contents">
  <!-- start template -->

  <div id="delete">
    <a class="remove" href="#">link</a>
  </div>

  <!-- end template -->
</div>

之后, your可以:

$( #contents ).on( click ,  div a.remove , function () {
  // ...
});

<http://api.jquery.com/live/"rel=“noreferer”> live( >,> for this -- 一项在重载或后向上调之前存在的内容——其行文如下:

$("a.remove").live("click", function () { /* ... */ });
$(document).on("click", "a.remove", function () { /* ... */ });
问题回答

我看一看整个法典,但我很幸运的是,你不要再把这套法典放在一边。

$("div").on("click", ".remove", function () {
// or $("#delete").on("click", ".remove", function () {
// or $(".remove").on("click", function () {

      // never enters...
}

新的法典已经列入OMD。

你们需要把活动听众的注意力放在创造的新内容上。 生计是因为它为像现在和将来这样的要素而努力的。

EDIT:

如果您希望点击手为能够动态装满的元素而工作,那么,你需要把活动手放在母物体上(不会有活力地装载),并给它一个像你这样充满活力的物体的挑选人:

$( #parent ).on("click", ".remove", function() {});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签