2012-07-12 26 views
0
沒有點擊

我現在用的是下頁稱爲capSlide一個jQuery腳本請疊加jQuery中

http://sundial.whistlerwebhosting.com/meetings-events/whistler-weddings

當通過圖像的透明疊加出現在頂部和標題用滑了用戶移動鼠標標題和更多信息鏈接。

我想讓整個div區域可點擊。我在想,因爲覆蓋層出現在它的這個div上面,我需要使鏈接處於活動狀態。我正在嘗試使用下面的jquery腳本,但它不起作用。

jQuery('.overlay').click(function(){ 
    window.location=jQuery(this).parent().find('a').attr('href'); 
     return false; 
}); 

的HTML輸出如下

<div class="ic_wrapper"> 
    <div id="capslide_img_cont11" class="ic_container"><img typeof="foaf:Image" src="/sites/all/themes/sundial/images/weddings/Wedding-Consulants.jpg" width="290" height="180" alt="Whistler Wedding Consulants" /> 
    <div class="overlay" style="display:none;"></div> 
    <div class="ic_caption"> 
     <h3>Wedding Consulants</h3> 
     <a href="/meetings-events/whistler-weddings/wedding-planners"> 
     <p class="ic_text">More Info</p> 
     </a> </div> 
    </div> 
</div> 

任何見解將不勝感激

回答

0

我會假設你的click事件沒有被註冊,因爲覆蓋DIV是腳本運行後添加。嘗試使用on()delegate() jQuery函數。例如:

jQuery(".ic_container").on("click", ".overlay", function(){ 
     window.location = jQuery(this).parent().find('a').attr('href'); 
     return false; 
}); 
+0

感謝您的建議我已經厭倦了這一點,但仍然沒有喜悅。在上面的示例中,.parent的用法仍然正確。實際的href位於.ic_container div而不是它的父級。或者,這是從overlay的角度來看的。 – 2012-07-13 01:58:13

+0

在我的例子中'this'的值是指'.overlay'選擇器 – Jlange 2012-07-13 18:18:09

0

在您的腳本文件(functions.js)中,您將單擊處理程序設置在文檔就緒功能之外。相反,把它裏面功能齊全:

jQuery(document).ready(function() { 
    jQuery('div#block-menu-menu-meeting-events-right.block div.content ul.menu li.last a').addClass('fancybox.iframe'); 

    // Your code has been moved to here... 
    jQuery('.overlay').click(function(){ 
     window.location=jQuery(this).parent().children().find('a').attr('href'); 
     return false; 
    });  
}); 

這使得等到頁面是將你的點擊處理程序之前準備就緒。