链式编程:
function Car(name, color) {
this.name = name;//属性=值
this.color = color;
this.show = function () {//方法=function () {}
alert(name + color);
return this;
}
this.speed = function (speed) {
alert("时速" + speed + "KM");
return this;//返回当前对象
}
}
//可通过 对此方法进行扩展(添加其他属性)
Car.prototype.money = function () {
alert("230W");
return this;
}
//窗体加载时调用当前对象中的方法
window.onload = function () {
//1. new Car("奥迪", "黑色").show();
// new Car().speed(800);
// new Car().money();
var car = new Car("奥迪", "黑色");
//链式编程:每次调用之后都返回它本身
car.money().show();//可以随意调用方法/属性
}
日期循环:
window.onload = function () {
//showtime();
setInterval(showtime, 5000); //定时->间隔指定时间 循环执行
setTimeout(showtime, 1000);//定时->等待执行时间,执行一次
}
function showtime() {
var date = new Date();
var year = date.getFullYear();
var mouth = date.getMonth();
mouth = mouth > 9 ? mouth : ("0" + mouth);
var da = date.getDate();
da = da > 9 ? da : ("0" + da);
var hour = date.getHours();
hour = hour > 9 ? hour : ("0" + hour);
var min = date.getMinutes();
min = min > 9 ? min : ("0" + min);
var sec = date.getSeconds();
sec = sec > 9 ? sec : ("0" + sec);
var Div = document.getElementById("div");
div.innerHTML = (year + "年" + mouth + "月" + da + "日" + hour + ":" + min + ":" + sec);
}