Jquery live - launching a fancybox iframe

一笑奈何 提交于 2019-12-13 04:56:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!