问题
So I have a an ajax table of results that have tags links that allows you to edit the entries.
Currently the links look like this <a href="edit.php?id=$id">Edit Entry</a>
What I want to do is open edit.php in a lightbox and send the id so as it is ajax I have to launch the lightbox using the live() function/
$("a.edit").live('click',function () {
//fancy box code goes here, open edit.php?id=$id
});
thanks
回答1:
First, you'll want to add class="edit"
to the links, so the jQuery selector can use it. After that, the following code should help out. ev.preventDefault()
will keep the browser from following the link, and allow you to implement the fancybox iframe instead.
$("a.edit").live("click",function(ev){
ev.preventDefault();
var id = this.href.match(/id=([0-9]*)/)[1];
$.fancybox({
href: "edit.php?id="+id,
type: "iframe"
})
});
You can add whatever fancybox settings you need, I just used the 2 for example.
Hope this helps.
来源:https://stackoverflow.com/questions/5477940/jquery-live-launching-a-fancybox-iframe