如何使用 javascript onClick 事件而不是链接调用 jQuery colorbox?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4405675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call jQuery colorbox with javascript onClick event instead of a link?
提问by DemonXTC
I want to call colorbox using javascript rather than a href link?
我想使用 javascript 而不是 href 链接调用 colorbox?
anyone know how I can do this?
有谁知道我怎么能做到这一点?
thanks.
谢谢。
回答by Memohotel Trip Organizer
The previous examples didn't work for me, but using the same idea, this does work:
前面的例子对我不起作用,但使用相同的想法,这确实有效:
<script>
function lightbox(){
$.colorbox({width:"80%", height:"80%", iframe:true, href:"/pagetoopen.html"});
}
</script>
<input type="button" value="open the box" onClick="lightbox()"/>
回答by jeremysawesome
This is off the top of my head. But I believe you could do something like this:
这是我的头顶。但我相信你可以做这样的事情:
<script type="text/javascript">
function call_cbox()
{
jQuery.colorbox({html:'<p>Hi There I was instantiated onclick!</p>'});
}
</script>
<a href="#" onclick="call_cbox(); return false;">Give me a colorbox... NOW! And don't forget the color.</a>
回答by Adam Luz
A mix of the two answers above worked for me:
上面两个答案的混合对我有用:
<script>
function call_cbox()
{
jQuery().colorbox({width:"900px", height:"600px", iframe:true, href:"/newsletter.html"});
}
</script>
回答by nixis
$("tr").click(function () {
$.colorbox({width:"900px", height:"600px", iframe:true, href:"http://www.google.com"});
});