2012-11-12 31 views
0

我正在爲每篇文章創建一個帶有jQuery擴展器框的電子通訊。默認情況下,每個擴展器框都關閉。我們會在每個問題前發送電子郵件預告,並提供每篇文章的鏈接。我想知道是否有任何方法可以展開我在鏈接代碼中鏈接的文章(或者可能位於指定鏈接的類中)。作爲參考,可以在這裏找到jquery文件:http://jjnursingnotes.com/NOV12/jquery.expander.js如何從另一頁面單擊鏈接時執行jQuery操作?

新聞簡報的HTML如下。 div層「擴展器」中的內容是我想在鏈接到http://jjnursingnotes.com/NOV12#01時插入到電子郵件預告器中時顯示的內容。

<div class="expander"> 
    <a name="01"></a> 
    <h1>Title</h1> 
    <h2>Subtitle</h2> 
    <h3>content</h3> 
</div> 
+4

是的,只要找到與給定的名稱(從'window.location的拉錨標記。散列「),遍歷它的父項,並展開它。 –

回答

1

不看你的擴展插件的細節,這裏是我在我自己的一個網站最近使用的解決方案。希望您可以自定義使用您正在使用的擴展器插件。我無法承擔變量解析的功勞,這起源於其他地方。

您的鏈接將需要設置爲這樣:

http://jjnursingnotes.com/NOV12?section=01 

然後你的JavaScript:

<script type="text/javascript"> 
// Redirect to Appropriate Section 
var urlParams = {}; 
(function() { 
    var match, 
     pl  = /\+/g, // Regex for replacing addition symbol with a space 
     search = /([^&=]+)=?([^&]*)/g, 
     decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, 
     query = window.location.search.substring(1); 

    while (match = search.exec(query)) 
     urlParams[decode(match[1])] = decode(match[2]); 
})(); 

$(document).ready(function(){ 
    if (urlParams['section'] != '') { 
     // urlParams['section'] variable = the ?section=XXX part of URL 
     // Here is where you would need integration with expanding box 

     // Assuming you use something like <div class="expander" id="sect01"> 
     // as your expander, something to this effect ought to work: 

     $("#sect" + urlParams['section']).find(".read-more a").click(); 

     // Position document at start of anchor 
     $('body,html').animate({ scrollTop: $("#sect" + urlParams['section']).offset().top }, 500); 
    } 
}); 
</script> 
+1

它是Karl Swedberg的擴展插件;) – danwellman

+0

謝謝!我試圖找到該插件的文檔 –

+0

現在給它一個鏡頭......謝謝! –

相關問題