2016-07-27 20 views
1

我添加了一個按鈕,Lightbox2標題:Click事件不Lightbox2標題燒製按鈕

<a href="link-to-img" data-lightbox="gallery" data-title=" 
    <div class='popup-button-container'> 
    <button class='order-button'>Order now</button> 
    </div>"><img src="img.jpg"> 
</a> 

按鈕是vsible但是當我嘗試做的onclick功能,這是行不通的:

$(document).on("click", ".order-button", function(e){ 
    e.preventDefault(); 
    console.log('Button clicked'); 
    $('#popup1').bPopup({ 
     speed: 850, 
     transition: 'slideDown', 
     modalColor: '#000000', 
     opacity: 0.5 
    }); 
    return false; 
}); 

相同的代碼適用於任何燈箱內容以外的類爲order-button的元素。

+0

你的內容在燈箱iframe中打開綁定事件?我想是的。這就是爲什麼js不工作 – SeeTheC

+0

您的html包含錯誤。你是否也調試過你的代碼? –

+0

@SeeTheC號開發工具中沒有iframe。 – Julia

回答

1
<a href="link-to-img" data-lightbox="gallery" data-title=" 
    <div class='popup-button-container'> 
    <button class='order-button'>Order now</button> 
    </div>"><img src="img.jpg"> 
</a> 

您正在編寫的代碼是數據標題。

<div class='popup-button-container'> 
     <button class='order-button'>Order now</button> 
     </div> 

正在被後

的$(document)。在渲染。

所以,你應該當收藏已經被渲染即標題被渲染

+1

謝謝:d更改'$(文件)。在(」點擊「,」.order-button「,功能(e){'到'$(」。lightbox「)。on(」click「,'.order-button',function(e){'and now it works! – Julia