在加载页面后创建的新元素上应用jquery propetities

在加载页面后创建的新元素上应用jquery propetities,jquery,twitter-bootstrap,modal-dialog,Jquery,Twitter Bootstrap,Modal Dialog,我对jquery和引导有问题。有一个带有动态表和模式的页面,每次打开时都会加载远程内容 当我第一次加载页面时,一切正常,但当我编辑表格时,更准确地说,当我添加或编辑行时,模态函数停止工作。在这种情况下,浏览器会直接打开远程页面,读取_properties.php 这是我如何调用模态的,每一行都有不同的id: <a data-target="#id_target" href="read_properties.php?id=xx"> 谢谢大家 试试这个 $("a[data-target

我对jquery和引导有问题。有一个带有动态表和模式的页面,每次打开时都会加载远程内容

当我第一次加载页面时,一切正常,但当我编辑表格时,更准确地说,当我添加或编辑行时,模态函数停止工作。在这种情况下,浏览器会直接打开远程页面,读取_properties.php

这是我如何调用模态的,每一行都有不同的id:

<a data-target="#id_target" href="read_properties.php?id=xx">
谢谢大家

试试这个

$("a[data-target=#id_target]").live(function(ev) {
  ev.preventDefault();
  var target = $(this).attr("href");

  $("#id_target .modal-body").load(target, function() { 
   $("#id_target").modal("show"); 
  });
});

单击将不会与动态html绑定。因此,您需要使用live listener。

解决方案很简单。我已编辑了第一行,并使用了文档正文上的.on事件:

$(document.body).on('click', "a[data-target=#ads]", function(ev){
  ev.preventDefault();
  var target = $(this).attr("href");

  // load the url and show modal on success
  $("#ads .modal-body").load(target, function() { 
    $("#ads").modal("show"); 
  });
});

似乎
#id_target
id被多次使用?@adeneo
id=“id_target”
仅用于模式,而我在表的每一行中使用
data target=“#id_target”
。谢谢,但它不起作用。我尝试
live.(函数(ev)
live.('click',函数(ev)
@user3108269-这是因为live在几年前就被弃用了,现在从jQuery中删除了,所以没有什么奇怪的。你能创建一个jsfiddle吗?谢谢,但我找到了解决方案。我用它编辑了我的问题
$(document.body).on('click', "a[data-target=#ads]", function(ev){
  ev.preventDefault();
  var target = $(this).attr("href");

  // load the url and show modal on success
  $("#ads .modal-body").load(target, function() { 
    $("#ads").modal("show"); 
  });
});