簡體   English   中英

單擊openlayer氣球(彈出)中的圖像時,打開顏色框

[英]Open colorbox when click on an image within openlayer ballon (popup)

從openlayer氣球(彈出)中單擊圖像時,我可以打開顏色框。 問題是它只能工作一次。 重新加載頁面后,它可以再次運行,但是只有一次。

當我查看chrome控制台時,出現以下錯誤:

“對象函數(a,b){返回新的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>

有人可以給我提示如何解決這個問題嗎?

提前致謝

嘗試避免內聯腳本處理程序。 選擇一個可以在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();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM