开发者

Expanding paragraph (html) for news section

I'm not sure how to go about this. I have a news section on a website I maintain and I'm trying to get it to display about 10 news items. Then I want to give users the option to click "more" for the rest, and th开发者_如何学编程e "less" for back to default. The document is xhtml and css and I'm trying to use as little javascript as possible. Any ideas?


If you want all the news article to actually be on the page, just invisible, versus having to request more from the server when the user clicks more, and you don't want to use the awesome javascript library called JQuery, then I suggest you get familiar with the Javascript method, document.getElementById. You can use it like this:

<a id="moreless" href="javascript:moretoggle()">More</a>
<div>some news</div>
<div id="morediv" style="display:none;">more news</div>

<script>
function moretoggle() {
    document.getElementById("morediv").style.display = document.getElementById("morediv").style.display == "none" ? "block" : "none";
    document.getElementById("moreless").innerHTML = document.getElementById("moreless").innerHTML == "More" ? "Less" : "More";
}
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜