jQuery Live-启动Fancybox iframe [英] Jquery live - launching a fancybox iframe

查看:55
本文介绍了jQuery Live-启动Fancybox iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个ajax结果表,其中包含标签链接,可让您编辑条目.

So I have a an ajax table of results that have tags links that allows you to edit the entries.

当前链接看起来像这样<a href="edit.php?id=$id">Edit Entry</a>

Currently the links look like this <a href="edit.php?id=$id">Edit Entry</a>

我想要做的是在灯箱中打开edit.php并发送ID,因为它是ajax,我必须使用live()函数启动灯箱/

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


   });  

谢谢

推荐答案

首先,您需要将class="edit"添加到链接中,以便jQuery选择器可以使用它.在那之后,下面的代码应该可以帮上忙. ev.preventDefault()将阻止浏览器跟踪链接,并允许您实施fancybox iframe.

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"
    })
});

您可以添加所需的任何fancybox设置,我仅以2为例.

You can add whatever fancybox settings you need, I just used the 2 for example.

希望这会有所帮助.

这篇关于jQuery Live-启动Fancybox iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆