[JavaScript]类之二
javascript 类定义4种方法
Java代码
/*
工厂方式--- 创建并返回特定类型的对象的 工厂函数 ( factory function )
*/
function createCar(color,doors,mpg){
var tempCar = new Object;
tempCar.color = color;
tempCar.doors = doors;
tempCar.mpg = mpg;
tempCar.showCar = function(){
alert(this.color + " " + this.doors);
}
return tempCar;
}
/*
构造函数方式--- 构造函数看起来很像工厂函数
*/
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.showCar = function(){
alert(this.color);
};
}
/*
原型方式--- 利用了对象的 prototype 属性,可把它看成创建新对象所依赖的原型
*/
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.drivers = new Array("nomad","angel");
} &nb
相关文档:
语法
oNewWindow = window.open( [sURL] [, sName] [, sFeatures] )
sURL 可选. URL 字符串 . 如果URL为空, 将以about:blank打开.
sName 可选. 字符串 描述打开窗口的名字(name). 可以做为form 和 a 标签的TARGET属性值 .
sFeatures 可选. 字符串 格式如"fullscreen=yes,toolbar=yes".channelmode = { yes | no | ......
源代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>验证邮箱地址合法性</title>
<sc ......
//把数据写入数据库
function
res(){
//获取输入值(myname和mymail是两个文本框的id)
var
uname = document.getElementById("myname"
).value;
var
umail = document.getElementById("mymail"
).value;
......
在web上编写菜单一直是比较头疼的事情,要是有个类直接套用就好了,最近又要做网站了,烦人,要求做的还是多级菜单,唉,废话少说,遇到问题就要解决啊,看代码:
function is(e, handler) {
if (e.type != 'mouseout' && e.type != 'mouseover ......
一个简单的javascript类定义例子
涵盖了javascript公有成员定义、私有成员定义、特权方法定义的简单示例
Java代码
<script>
//定义一个javascript类
function JsClass(privateParam/*&n ......