单击openlayer气球(弹出窗口)中的图像时,我可以打开colorbox。问题是它只起作用一次。在我重新加载页面后,它再次工作,但只有一次。
当我查看chrome控制台时,我得到了这个错误:
“对象函数(a,b){return new e.fn.init(a,b,h)}没有方法‘colorbox’。”
外部.js文件中的代码为:
function call_colorbox(url) {
jQuery.colorbox({href: url, height: "80%", width: "80%"});
};openlayer气球(弹出窗口)中的代码是:
<a href="#" onClick="call_colorbox('/mypage.html')"><img src="myimg.jpg" alt="title" title="title" /></a>有人能给我一个提示如何纠正这个问题吗?
提前感谢
发布于 2013-11-17 19:32:42
尽量避免内联脚本处理程序。选择可以在javascript中作为目标的标识符,例如.colorbox
<a href="#" class="colorbox" data-url="example.html"> .. </a>然后在JS中(假设加载了jQuery库):
$('body').on('click', '.colorbox', function (event) {
$.colorbox({href: $(this).data('url'), height: "80%", width: "80%"});
event.preventDefault();
});https://stackoverflow.com/questions/20029496
复制相似问题