您的位置:首页 > Web前端 > JavaScript

两个javascript小测试例子 类和json函数

2015-08-27 16:26 447 查看
两个javascript小测试例子 类和json函数

one.html

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>function this 的使用</title>

</head>

<body>

<script type="text/javascript" language="javascript">

cls=function(data){

this.showA=function (a){

alert(a);

};

//showA('showA');

this.showA("ccc")

function showB(b){

alert(b);

};

showB("ddd")

function showData(data){

alert(data);

};

}

var c=new cls("simone");

c.showA("asmone");

c.showB("tt");

cls.showB("b");

cls.showData("wang");

alert(cls("simone"));

</script>

</body>

</html>

two.html

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>function : 的使用</title>

</head>

<body>

<script type="text/javascript" language="javascript">

var FN=function(s){

alert('fn');

alert(s);

return{

nopar:function(){alert('nopar')},

onepar:function(p){alert('onepar');alert(p)},

shows:function(){alert(s)},

shows2:function(s){alert(s)}

}

}

fn=new FN('onefn');

fn.nopar();

fn.onepar('ts');

fn.shows();

fn.shows2('tbb');

alert('******************');

var FN2={

one:function(){alert('one')},

two:function(p){alert(p),alert(this)},

three:function(){

this.one();

alert('three');

function in_three(){

alert('in_three');

};

this.this_three=function(){

alert('this_three');

};

}

};

FN2.one();

FN2.two('fn2 two');

FN2.three();

var three2=FN2.three;

alert('########');

var th=new three2();//去掉this.one()这一语句后,可以new成功

th.this_three();

</script>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: