2017-02-03 56 views
0

HTML代碼鏈接上負載插件swipebox:消防與包括散列標籤

<a id="image1" href="images/1.jpg" class="swipebox" title="My Caption"> 
    <img src="images/1mini.jpg" alt="image" /> 
</a> 
用於當用戶與鏈接結尾進入「#1」

<script type="text/javascript"> 
    $(document).ready(function(){ 
     if(window.location.hash == "#1") { 
      $('#image1').swipebox(); 
     } 
    }); 
</script> 

燒製普金

JS代碼我想出了,js代碼

$('#image1').swipebox(); 

只有當我點擊圖像。但我在頁面加載期間需要它已經被滿足了。

+0

解釋調試代碼後不起作用。 –

+0

我不知道如何調試。我明白'.swipebox();'調用插件,所以我做到了。當我使用鏈接#1提醒消息時,它顯示,這意味着問題與'$('#1').swipebox();' –

+0

'id =「1」'無效。請檢查此:http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – vijayP

回答

1

在頁面加載時打開swipebox;你可以請用以下代碼嘗試:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     if(window.location.hash == "#1") { 
      $('#image1').swipebox(); 
      $('#image1').click();//click the image programmatically 
     } 
    }); 
</script> 
+0

非常感謝。一切正在工作 –

+0

歡迎@RustamPaskaev ...':)'! – vijayP