2014-05-09 30 views
0

試圖檢查當前網址是否具有哈希值#video-value,如果它確實運行用於同一頁面上的標記鏈接操作的相同點擊操作。檢測網址哈希值以觸發點擊事件

jQuery代碼:

<script type="text/javascript"> 
jQuery(document).ready(function() { 
function showVideo() { 
    var $anchor = jQuery(this), 
     url = $anchor.data("url"), 
     title = $anchor.data("title"); 
    jQuery("#help-video-iframe").css("visibility", "hidden"); 
    jQuery("#help-video-iframe").addClass("loading"); 
    jQuery("#help-video-iframe").load(function() { 
     jQuery("#help-video-iframe").css("visibility", "visible"); 
    }); 
    jQuery("#help-video-div-label").empty().append(title); 
    jQuery("#help-video-iframe").attr("src", url); 
} 

jQuery(function() { 
    jQuery("#help-videos-list a").click(showVideo); 
    jQuery("#help-videos-list .caption").equalizeHeights(); 
}); 

}); 

</script> 

回答

0

來檢查任何散列值的存在:

if (window.location.hash) { 
    //do something 
} 

要手動設置散列,你可以這樣做:

window.location.hash = 'some-hash'; 
+0

對不起,我不是非常清楚,我只是想知道它是否有任何哈希值不是明確的。我如何獲得散列值,就像我點擊頁面上的一樣。也允許在我的幾個的頁面上標準的onlick。 – esternle

+0

我不確定你在問什麼。查看我更新的一般概念答案。 – pmandell

+0

我想使用showVideo()的相同功能。對於頁面點擊以及網址末尾都有散列。但現在我需要將散列值傳遞給showVideo()函數,以將該項目與從點擊操作中獲取的jquery(this)相關聯。 – esternle