如何使用javascript onClick事件而不是链接调用jQuery colorbox?

Dem*_*XTC 15 javascript jquery colorbox

我想用javascript而不是href链接调用colorbox?

有谁知道我怎么做到这一点?

谢谢.

小智 19

前面的例子对我不起作用,但使用相同的想法,这确实有效:

<script>
function lightbox(){    
  $.colorbox({width:"80%", height:"80%", iframe:true, href:"/pagetoopen.html"});
}
</script>

<input type="button" value="open the box" onClick="lightbox()"/>
Run Code Online (Sandbox Code Playgroud)


jer*_*ome 5

这是我的头脑.但我相信你可以这样做:

<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>
Run Code Online (Sandbox Code Playgroud)