1
$.colorbox({href:"login.php"}); //this Works (opens login.php)
$(this).click(function(){
$.colorbox({href:"login.php"}); //Doesn't work (opens parent page after 5 sec and breaks colorbox)
}
可能是什麼問題?
$.colorbox({href:"login.php"}); //this Works (opens login.php)
$(this).click(function(){
$.colorbox({href:"login.php"}); //Doesn't work (opens parent page after 5 sec and breaks colorbox)
}
可能是什麼問題?
好吧,假設你複製和粘貼代碼,你錯過了一個paren。您還應該撥打e.preventDefault()
以防止鏈接?/按鈕?從做它打算做的事情。
$(this).click(function(e){
//Doesn't work (opens parent page after 5 sec and breaks colorbox)
$.colorbox({href:"login.php"});
//Prevent default so the button?/link? doesn't do what it's intended to do
e.preventDefault();
});
不知道什麼this
指的是在你的範圍,但如果它是一個錨或提交按鈕,你可能想通過返回false就取消它的默認操作:
$(this).click(function() {
$.colorbox({ href: 'login.php' });
return false;
});
它必須是e.preventDefault();正常工作 謝謝! – Miro