获取隐藏文本并将其放在div标记中
单击锚点标记时,将显示“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>
试试这个: http://jsfiddle.net/MZga6/
$('a').bind('click.myClick', function() {
var that = $(this);
$('#anotherDiv').text(that.parent().find('.desc').text()).show();
});
当列表项被点击时,获取子描述。然后在另一个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);
});
它,当我尝试显示隐藏element.So我应该能够使文本可见,然后再插入到anotherDiv返回空。 – neelmeg 2012-02-07 21:26:36
@web_dev - 那是因为你的anotherDiv是隐藏的。你可以用'show'来显示它,或者使用'fadeIn'或'slideDown'来很酷的使用。 – mrtsherman 2012-02-07 22:20:19
获得它的荣誉! – neelmeg 2012-02-07 21:45:35
确保你在你的答案中发布你的代码。这样未来的访客可以从你的知识中受益。 – mrtsherman 2012-02-07 22:14:24