[英]How to edit link that show modal box in jQuery
I have a problem where I try to show a modal box, it's when I append some a href="" links to my that is on my index page. 我在尝试显示模式框时遇到问题,那就是在索引页面上向我附加一些href =“”链接时。
I have this in my jQuery script: 我的jQuery脚本中有这个:
$(document).ready(function(){
$('a').click(function () {
// Dialog
$("#feed"+$(this).attr('id')).dialog({
bgiframe: true,
width: 400,
modal: true
});
return false;
});
});
And this is the link I have on the index page: 这是我在索引页面上的链接:
<p><a href="#" id="0">Feed 0</a></p>
If I add the links on the index page it works, but if I empty my div and post new links without any reload they stop to work. 如果我在索引页面上添加链接,则可以使用,但是如果我清空div并发布新链接而不进行任何重新加载,它们将停止工作。 No modal box shows, how can I make the jQuery get that the links are there even if they apere after the document is loaded? 没有模态框显示,如何使jQuery即使链接在文档加载后仍然存在,链接也在那里?
I need a jQuery function that allows me to add links after the document has been loaded. 我需要一个jQuery函数,允许我在文档加载后添加链接。
Thanks in Advance Daniel 在此先感谢Daniel
Use .live()
to attach a handler to document
that'll work on current and future links, like this: 使用.live()
将处理程序附加到将在当前和将来的链接上工作的document
,如下所示:
$(function(){
$('a').live('click', function () {
$("#feed"+this.id).dialog({
bgiframe: true,
width: 400,
modal: true
});
return false;
});
});
As an aside, your id
's aren't valid in HTML4 (they can't start with a number, not that they'll realistically cause any issues here, just pointing it out). 顺便说一句,您的id
在HTML4中无效(它们不能以数字开头,不是这样,实际上它们会在这里引起任何问题,只是指出来)。 They are valid in HTML5 however :) 它们在HTML5 中有效,但是:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.