翻版HeadFirstJS例子,日记本的实现

可耻的盗版了。。

HeadfirstJs全书的配套代码可以在csdn等各处下载到。

本处仅仅为手打练习。。用于记载练习进度

<!-- 1.使用构造函数创建类的实例 -->
<!-- 2.调用函数遍历展示类的实例 -->
<!-- 3.增加一个全部显示的按钮 -->
<!-- 4.修改了显示风格 -->
<!-- 5.使用Date类进行时间显示,使用类Date,并逐一获取年月日 -->
<!-- 6.增加了按时间排序功能 使用sort函数使用自己的函数指针进行排序,将日期从大到小排列-->

<html>
<head>
	<title>Share Index of BenBen</title>
	<script type = "text/javascript">
	
	function Test(){
	    alert("Hello ,you sucessful open the window!");
	}

	// 构造分享目录类
	function Diary(date, content) {
	    this.date       = date;
	    this.content    = content;
	}

	//构造条目
	var index = [ new Diary(new Date("3/23/2013"), "A good day!"),
	              new Diary(new Date("3/24/2013"), "Want to sleep!"),
	              new Diary(new Date("3/25/2013"), "Work all day!")];

	//显示数据
	function ShowItem(num) {
	    if (!num) {
	        num = index.length;
	    }
	    index.sort(function(diary1, diary2) { return diary2.date - diary1.date; });
	    var i = 0; indexText = "";
	    while (i < index.length && i < num) {
	        if (i % 2 == 0) {
	            indexText += "<p style = 'background-color:#EEEEEE'>";
	        }
	        else
	            indexText += "<p>";
	        indexText += "<strong>"
	        + (index[i].date.getMonth() + 1 )+ "/"
	        + (index[i].date.getDate() + "/")
	        + (index[i].date.getFullYear())
	        + "</strong><br/>" + index[i].content + "</p>";
	        i++;
	    }
	    document.getElementById("Show").innerHTML = indexText;
	}
	</script>
</head>
<body onload = "ShowItem(1);">
<div id = "Show"> </div>
<input type="button" id = "showAll" value = "Show All diary" onclick = "ShowItem();">
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值