[英]How to call jQuery colorbox with javascript onClick event instead of a link?
I want to call colorbox using javascript rather than a href link? 我想用javascript而不是href链接调用colorbox?
anyone know how I can do this? 有谁知道我怎么做到这一点?
thanks. 谢谢。
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()"/>
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>
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>
$("tr").click(function () {
$.colorbox({width:"900px", height:"600px", iframe:true, href:"http://www.google.com"});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.