2012-06-06 87 views
0

這是可能的jQuery或其他方法?基本上,我在屏幕上顯示的div中有一個書籤超鏈接。它鏈接到另一個未顯示的div中的書籤標籤。當用戶單擊書籤鏈接時,可能檢測包含書籤的div的屬性並將該div顯示設置爲顯示嗎?單擊,搜索書籤並顯示書籤所在的div div

<div class="cpecontent" id="content_2"> 
    <h2><br /> 
    <a name="0.1__Toc320283140"> </a> <a name="0.1__Toc325358918"> </a>Determine All Sources of Income (Taxable and Non-Taxable)</h2> 
    <p><br /> 
    Reaching into the bag you pull out an amorphous jumble of paper. There are receipts, a stapled stack of credit card statements, a few 1099s, a W-2, a manila envelope labeled "investments," some check stubs, and one artificial fingernail. "What is all this?" you inquire. </p> 
    <p><br /> 
    "Monday nights at 6:15. It's all about the lottery and I play a woman who runs this magical machine that grabs numbered ping pong balls. It's like a big popcorn machine. My character presses a button that makes the machine grab a ball out of the air. When the machine grabs a ball, she has to turn it so the number faces the camera. There's no dialogue yet, but my manager says they're probably going to expand my role." </p> 
    <p><br /> 
    <!--ON Click for this Bookmark, set the div below to display:show;--> 
    <a href="#0.1__Gross_Income" title="_Gross_Income"> <span> For more on this topics - see Appendix A </a> </p> 
</div> 


<!--A LOT OF CONTENT IN BETWEEN--> 

<!--This DIV is hidden right now, but we want to try and show it--> 
<div class="cpecontent" id="content_11" style="display:none;"> 
    <h2><br /> 
    <a name="0.1__Toc325358937"> </a> <a name="0.1__Gross_Income"> </a>Gross Income</h2> 
    <p><br /> 
    All of the following constitute possible sources of Gross Income:</p> 
    <p style="margin-bottom:0pt;line-height:12pt">Wages</p> 
    <p style="margin-bottom:0pt;line-height:12pt">Self-employment income</p> 
    <p style="margin-bottom:0pt;line-height:12pt">Partnership and S corporation income</p> 
</div> 

回答

0
$('a[href^="#"]').click(function(){ 
    $('a[name="'+this.href.replace('#', '')+'"]').show(); 
}); 

BTW,我認爲這些鏈接被稱爲錨沒有書籤。

+0

此代碼如何設置div顯示?你找到了書籤,但是可以檢測書籤所在的div並顯示該div? – user988256

+0

我認爲你需要''.parents('div')。show();' – romo

+0

這個.ref參數會覆蓋整個URL,例如'http://domain.com/index-page-繼續職業教育 - 子頁面顯示課程-27.htm#0.1__Gross_Income。有沒有辦法在#上拆分字​​符串? – user988256