簡體   English   中英

滿足條件時阻止Jquery圖像工具運行

[英]Prevent Jquery image tool from running when condition met

正在使用名為LightBox的jquery工具。 它是顯示圖像的工具。 它工作正常,但是如果ajax調用返回了某個值,我就需要阻止燈箱功能的發生。 現在,這個問題不是關於ajax調用的,而是關於如何在單擊鏈接后如何阻止LightBox進行操作?

這是使用LightBox彈出圖像的鏈接(工作正常)

<a id="test_id" href="http://localhost/histogram.do" data-lightbox="histogram1"> Click Me </a>

這是我的笨拙代碼,試圖阻止LightBox繼續運行。 發生警報,​​但單擊確定后,燈箱彈出窗口仍然出現。 有任何想法嗎?

$("#test_id").click(function(e){
    alert("hello");
    e.stopPropagation();
})

該庫使用jQuery .on()將click事件綁定到元素。

您是否嘗試過e.stopImmediatePropagation()

http://api.jquery.com/event.stopImmediatePropagation/

它阻止其他任何處理程序觸發,然后調用stopPropagation()以防止冒泡。

此外,要防止元素點擊時跟隨href鏈接,可以使用e.preventDefault()

http://api.jquery.com/event.preventDefault/

暫無
暫無

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

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