我想做这样的事情:
<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',就像我上面写的那样。但正如我所写,它不起作用。请帮忙 :)
文档准备好后,绑定按钮单击事件。
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的更多信息
尝试
$("#myLink").click();
它应该触发onclick
事件。