单击表格行应打开一个精美框

发布于 2024-12-19 06:15:04 字数 1228 浏览 3 评论 0原文

我尝试打开一个通过单击表行上任意位置触发的 fancybox。单击一行后,我在 Firebug 控制台中看到以下消息:

递归过多 http://code.jquery.com/jquery-1.7.js 2925行

这是我的 HTML:

<table id="allItems">
    <tr class="itemRow">
        <td><a href="http://www.google.com" class="foo">foo</a></td>
        <td>bar</td>
    </tr>
    <tr class="itemRow">
        <td><a href="http://www.bing.com" class="foo">bar</a></td>
        <td>bar</td>
    </tr>
</table>

这是我的 javascript:

var itemRow = $('#allItems tr.itemRow');

itemRow.click(function(e){
    e.preventDefault();  
    $(this).find('.foo').trigger('click');
});


$('.foo').fancybox({
    'href' : $(this).attr('href'),
    'width'             : '100%',
    'height'            : '100%',
    'autoScale'         : false,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'type'              : 'iframe'
});

您可以在这里找到一个实例:http://jsfiddle.净/svebal/zQ8FZ/

I try to open a fancybox triggered by a click anywhere on a table row. After click on a row, I achieve this message in the Firebug console:

too much recursion
http://code.jquery.com/jquery-1.7.js
Line 2925

Here is my HTML:

<table id="allItems">
    <tr class="itemRow">
        <td><a href="http://www.google.com" class="foo">foo</a></td>
        <td>bar</td>
    </tr>
    <tr class="itemRow">
        <td><a href="http://www.bing.com" class="foo">bar</a></td>
        <td>bar</td>
    </tr>
</table>

Here is my javascript:

var itemRow = $('#allItems tr.itemRow');

itemRow.click(function(e){
    e.preventDefault();  
    $(this).find('.foo').trigger('click');
});


$('.foo').fancybox({
    'href' : $(this).attr('href'),
    'width'             : '100%',
    'height'            : '100%',
    'autoScale'         : false,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'type'              : 'iframe'
});

A live example you can find here: http://jsfiddle.net/svebal/zQ8FZ/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迟到的我 2024-12-26 06:15:04

.trigger() 在一些浏览器/jquery 插件上非常不可靠。你想做:

var itemRow = $('#allItems tr.itemRow');

itemRow.click(function(e) {
    e.preventDefault();
    $.fancybox({
        'href': $(this).find('.foo').attr('href'),
        'width': '100%',
        'height': '100%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });
});

.trigger() is pretty unreliable on several browsers/jquery plugins. You want to do:

var itemRow = $('#allItems tr.itemRow');

itemRow.click(function(e) {
    e.preventDefault();
    $.fancybox({
        'href': $(this).find('.foo').attr('href'),
        'width': '100%',
        'height': '100%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });
});
怼怹恏 2024-12-26 06:15:04

实际上,您需要的唯一脚本是:

$('.foo').click(function(){
    $.fancybox({
            'href' : this.href,
            'width'             : '100%',
            'height'            : '100%',
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'              : 'iframe'
    });
    return false;
});

Actually, the only script you need is this:

$('.foo').click(function(){
    $.fancybox({
            'href' : this.href,
            'width'             : '100%',
            'height'            : '100%',
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'              : 'iframe'
    });
    return false;
});
半边脸i 2024-12-26 06:15:04

如果您想在单击 tr 上的任何 td 后显示灯箱,则必须更改此行:

 $(this).find('.foo').trigger('click');

对此,

 $(this).next().find('.foo').trigger('click');

这将找到下一个元素下类为 foo 的元素

if you want to show the lightbox after clicking any td on the tr you must change this line:

 $(this).find('.foo').trigger('click');

to this

 $(this).next().find('.foo').trigger('click');

this finds the element which class is foo under the next element

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文