<p id="pid"></p>
<script>
var mytime = setInterval(function (){showTime();},1000); //每隔1秒调用一次showTime函数
function showTime(){
var pnode=document.getElementById("pid");
var time=new Date();
var t=time.toLocaleTimeString();
pnode.innerHTML=t;}function stopTime(){clearInterval(myTime);//停止时间刷新
}
</script>
6.3 History对象
window.history对象包含浏览器的历史(url)的集合。
方法
描述
history.back()
功能与浏览器点击后退按钮效果一样
histoty.forward()
功能与浏览器点击向前效果一样
history.go()
进入历史的某个页面
<a href="006.html">进入006</a>
<button οnclick="goone()">按钮</button>
<script>
function goone(){
history.go(1);}
</script>
<button οnclick="go()">按钮6</button>
<script>
function go(){
history.back();}
6.4 Location对象
window.location对象用于获取当前页面的地址(URL),并把浏览器定向到新的页面。
对象的属性
描述
location.hostname
返回web主机的域名
location.pathname
返回当前页面的路径和文件名
location.port
返回web主机端口
location.protocol
返回所使用的web协议(http://或https://)
location.href
返回当前页面的URL
location.assign()
方法加载新的文档
host
主机名和端口号
6.5 Screen对象
window.screen对象包含有关用户屏幕的信息。
属性
描述
screen.availWidth
可用的屏幕的宽度
screen.availHeight
可用屏幕的高度
screen.Height
屏幕高度
screen.Width
屏幕宽度
七、面向对象
//面向对象的操作
// 1.第一种
var people={name:"ning",
age:10,
say:function(){alert(this.name);}};alert(people.age);
people.say();
function person(){
this.name="ning";
this.age=10;
this.say=function (){alert("现在22:29");}}
var p=new person();
p.say();
//2. 第二种
/*
function people(){
}
people.prototype={
name:"ning",
age: 10,
say:function () {
alert("我是第二种");
}
}
people.prototype.speak=function () {
alert("说话");
}
var p=new people();
p.say();
p.speak();
*/
//3. 第三种 用function来模拟类继承
/*
function people() {
}
people.prototype.say=function () {
alert("我是父类方法");
}
function Student() {
}
Student.prototype=new people(); //Student继承people
var s=new Student(); //创建对象
s.say(); //能够调用父类的方法
var superSay=Student.prototype.say;
Student.prototype.say=function () {
superSay.call(this);
alert("重写父类的say方法");
}
s.say();//这里想要调用父类的Say方法,需要先用surperSay保存父类的say方法,然后在子类重写的方法中调用superSay.call(this)即可
*/
// 4.面向的思维:封装
/*
//格式:
(function () {
//这里填入上面的代码进行封装,比如对people封装;
window.XXX=XXX;//将这个XXX传给最高的window对象,这样就可以通过window访问封装的内容了
}())
//封装举例:
(function () {
function people() {
}
people.prototype.say=function () {
alert("我是父类方法");
}
window.people=people;
})
*/
//4. 第四种 这里没有封装,如果要封装,方法和上面一样;
/*
function people() {
var _this={};
_this.name="ning";
_this.age=10;
return _this;
}
function Student() {
var _this=people();
return _this;
}
var s=Student();
alert(s.age+s.name); //能够访问父类属性
*/