正如Colorbox Docs
可以設置回調「的OnOpen」(和「的onLoad」也有可能),這顏色框前應激發提到開始在目標指定加載的內容給你機會去修改它
$(function() {
$(".button").colorbox({
width: "50%",
height: "50%%",
iframe: true,
href: "/abc",
opacity: 0.6,
onOpen: function(){
// modify target here
}
});
});
UPDATE 也許更簡單的方案 - 顏色框允許使用的函數,而不是靜態值的
$(function() {
$(".button").colorbox({
width: "50%",
height: "50%",
iframe: true,
href: function(){
// Since I can't see your markup I can't provide exact solution
// but if your .button elm is an anchor then use
var url = $(this).attr('href');
// if you are obtaining the url from diff. elm, grab it from there
// such as $('#your_element).attr('href')
return url;
},
opacity: 0.6
});
});
嗨凱文,是的你是對的。最簡單的方法是讓href屬性從函數中獲取它的值:href:function(){return「/ hRef」}, – FloatLeft
爲''鏈接添加'e.preventDefault();'。 – AfromanJ