2012-02-07 90 views
0

單擊錨點標記時,將顯示「anotherDiv」。獲取隱藏文本並將其放在div標記中

使用jQuery,我希望能夠在每個li onClick中獲取描述,並將其插入到「anotherDiv」區域,該區域同樣可以在錨點標記的onClick上看到。說明文字最初設置爲不顯示任何內容。

<style> 
    .desc{ 
    display:none; 
    } 

    #anotherDiv{ 
     display: none; 
    } 

</style> 

     <li style="overflow: hidden; float: none; width: 158px; height: 125px;"> 
        <a onClick="return addPlayer(952541791001, 661361792001, 600, 320)" id="no8" class="video-pop"> 
         <img width="132" height="75" alt="" src="image.jpg"> 
        </a> 
        <div class="label">The label goes here......</div> 
        <div class="desc">The description goes here.....</div> 
       </li> 
     <li style="overflow: hidden; float: none; width: 158px; height: 125px;"> 
        <a onClick="return addPlayer(952541791001, 661361792001, 600, 320)" id="no10" class="video-pop"> 
         <img width="132" height="75" alt="" src="image.jpg"> 
        </a> 
        <div class="label">The label goes here......</div> 
        <div class="desc">The description goes here.....</div> 
       </li> 
    ------------------------------------------------------------- 
    <div id="anotherDiv"></div> 

回答

1

試試這個: http://jsfiddle.net/MZga6/

$('a').bind('click.myClick', function() { 
    var that = $(this); 
    $('#anotherDiv').text(that.parent().find('.desc').text()).show(); 

}); 
+0

獲得它的榮譽! – neelmeg 2012-02-07 21:45:35

+1

確保你在你的答案中發佈你的代碼。這樣未來的訪客可以從你的知識中受益。 – mrtsherman 2012-02-07 22:14:24

0

當列表項被點擊時,獲取子描述。然後在另一個DIV中插入它的html。

$('li').click(function() { 
    $('#anotherDiv').html($(this).children('.desc').html()); 
}); 

//a more readable format to help you understand 
$('li').click(function() { 
    //$this is the clicked list item. We search its children for class `desc` and get contents 
    var desc = $(this).children('.desc').html(); 
    //set anotherDiv's contents 
    $('#anotherDiv').html(desc); 
}); 
+0

它,當我嘗試顯示隱藏element.So我應該能夠使文本可見,然後再插入到anotherDiv返回空。 – neelmeg 2012-02-07 21:26:36

+0

@web_dev - 那是因爲你的anotherDiv是隱藏的。你可以用'show'來顯示它,或者使用'fadeIn'或'slideDown'來很酷的使用。 – mrtsherman 2012-02-07 22:20:19

相關問題