今天 先复习了下函数的封装和继承:
函数的封装:1、function dianshi (color,size,brand) {
var Tv={};
Tv.color=color;
Tv.size=size;
Tv.brand=brand;
Tv.look=function () {
alert("看电视");
}
Tv.play=function () {
alert("玩");
}
Tv.dvd=function () {
alert("DVD");
}
return Tv; //这个地方一定要返回;
}
var ds=dianshi("red","30inch","sony");
//alert(typeof ds)
alert(ds.color)
var ds1=dianshi("blue","40inch","changh");
alert(ds1["size"])
2、
function fun1(name,year){this.name=name;
this.year=year;
}
fun1.prototype.play=function(){ //注意一定要是函数名.prototype.play
alert("我要玩")
};
var cc=new fun1("xl","26");
var dd=new fun1("z",24);
alert(cc.year);
cc.play();
alert(dd.name);
函数继承:function preson(name,year){
this.name=name;
this.year=year;
this.say=function(){
alert("我说")
}
}
function student(){
this.name=name; //我们利用继承其它函数的属性和方法时,该函数一定要有对应的变量
//preson.call(this)??这个还得考证?
}
student.prototype=new preson();
var cc=new student("xl");
cc.say();
alert(cc.name)
var dd=new student();
cc.say.call(dd);//给cc对象所具有的say方法给dd
*************************************************************************************************
对样式的操作:
1、通过ID或者ClassName来批量操作;
2、行内样式的操作:
---对象.style.属性(获取)
– 对象.style.属性=值 (设置、更改、添加属性)
3、通用的获取属性值的方法:
IE:对象.currentStyle.属性;
FF:getComputedStyle(对象,null).属性;