开发者

Opening Jquery fancybox from a function

开发者 https://www.devze.com 2023-01-19 12:48 出处:网络
I can\'t seem to find the answer to this question anywhere so I ask here. I already use successfully fancybox like this:

I can't seem to find the answer to this question anywhere so I ask here. I already use successfully fancybox like this:

$("#editor").fancybox({
            'width' : 1000,
            'height' : 600,
            'autoDimensions' : false,
            'autoScale' : false,
            'ajax' : {
                type : "POST",
   开发者_如何学C             data : varstring
            }
        })

Now the problem is that due to new necessities the varstring must contain unique data for each of the link that should open the fancybox window. Tha way I was picturing it is like this:

function openEditor(elementid,sid,pid,gid){
    $("#"+elementid).fancybox({
            'width' : 1000,
            'height' : 600,
            'autoDimensions' : false,
            'autoScale' : false,
            'ajax' : {
                type : "POST",
                data : 'varstringnotimplemented'
            }
        });
    //$("#"+elementid).trigger('click');
    return false;
}

It doesn't work, if I uncomment the trigger I get a:

uncaught exception: Syntax error, unrecognized expression: #

Even if I manage to get this thing working is pretty ugly, is there a better way to do this?

Thank you


It would be better to pass the actual object instead of an id.

function openEditor(element,sid,pid,gid){
    var $element = $(element);
    var dataString = '??';
    var ajaxSettings = {
                type : "POST",
                data : dataString
            };

    $element.fancybox({
            'width' : 1000,
            'height' : 600,
            'autoDimensions' : false,
            'autoScale' : false,
            'ajax' : ajaxSettings 
        });
    $element.trigger('click');
    return false;
}

link would be

<a href="javascript:void(0);" onclick="openEditor(this,'some','other','params')">text</a>

you cannot pass the actual object if you send it trough the href, you can send it through the onclick

0

精彩评论

暂无评论...
验证码 换一张
取 消