使用 onclick to open an ajax content into a fancybox

问题描述 投票:5回答:2

我想做这样的事情:

<a href="javascript:void(0);" id="myLink" onclick="$(this).fancybox({href : 'myPage.php'});">Open ajax content</a>

请注意,我不能使用这样的脚本:

<script type="text/javascript">
   jQuery(document).ready(function(){
      $("#myLink").fancybox({href : 'myPage.php'});
   });
</script>

我想从<a> onclick元素触发一个fancybox。但是对于这个onclick函数,它必须有来自fancybox的'href',就像我上面写的那样。但正如我所写,它不起作用。请帮忙 :)

javascript jquery onclick fancybox
2个回答
0
投票

文档准备好后,绑定按钮单击事件。

jQuery(document).ready(function(){

      $("#myLink").click(function() {
          $(this).fancybox({href : 'myPage.php'});
      });

 });

那么你的元素中就不需要javascript代码了。

<a href="#" id="myLink">Open ajax content</a>

查看jQuery click function的链接以及有关observer pattern的更多信息


0
投票

尝试

$("#myLink").click();

它应该触发onclick事件。

© www.soinside.com 2019 - 2024. All rights reserved.