I am using a lightbox script, Clearbox. For various reasons ( main one is I can't use a link to open the lightboxin this particular setup), I need to set up a function as follows to open an image in the lightbox:
function initCBox(){
var img1 = $(select.currentImg).attr('src');
var label = $(s开发者_高级运维elect.currentImg).attr('alt')
CB_Open('href=img1,,title=label');
}
Clearbox wants the href to be an actual link but I need it to be the img1 var. I'm a newbie with this so any help or direction would be appreciated.
CB_Open('href='+img1+',,title='+label);
you need to concatenate it in
You could use string concatenation to build that parameter string before you pass it to CB_Open:
function initCBox(){
var img1 = $(select.currentImg).attr('src');
var label = $(select.currentImg).attr('alt')
CB_Open('href=' + img1 + ',,title=' + label);
}
Alternatively, you can see if CB_Open can take an "options hash" object - this is cleaner, if it's supported:
function initCBox(){
var img1 = $(select.currentImg).attr('src');
var label = $(select.currentImg).attr('alt')
CB_Open({
href: img1,
title: label
});
}
Hope that helps!
CB_Open('href=' + img1 + ',,title=label');
精彩评论