2249
0
admin
IP 编辑 禁止 帖子 清理
<html> <head> <title></title> </head> <body> <input id="a" value="a"/> <input id="b" value="b"/> </body> </html> <script> function test(){ this.value=1; this.get=function(){ alert(this.value); } } var T=new test(); document.getElementById('a').onclick=function(){ T.get(); } document.getElementById('b').onclick=T.get; </script>
使用道具
316
2
xiaomei
管理
1674
WR
1546
一个人的时光
<input id="a" value="a"/> 输出1 <input id="b" value="b"/> 输出b
1576
liufangyuan
结果分别为 1 b var T=new test();此时function test(){}作为一个类可以声明对象,对象名为T 当点击a时,调用function函数,执行函数体中this.get,输出结果为1 单击b时,执行T.get,输出本对象,b
1636
renmihe
1
b
在body中有a和b两个输入框,初值为a和b
在执行new test()时调用function test(),在a文本框中值为1,当点击a文本框时,显示输出
执行document语句,点击a输入框时,执行输出值1
执行document语句,点击b输入框时,执行输出值b
1450
Sarbr
第一个是1
在test方法中已改变a为1
第二个是b
1721
XIAOC
a输出的是1
b输出的是b
1510
zhangjialong
第一个text中的值为a,点击弹出 1。
第二个text中的值为b,点击弹出b。
1451
gaoye
1700
song
值分别为1 和b
<html> <head> <title></title> </head> <body> //定义一个文本框 id为a <input id="a" value="a"/> //定义另一个文本框 id为b <input id="b" value="b"/> </body> </html> <script> //test() 方法 function test(){ //value值为1 this.value=1; //get:创建的对象 this.get=function(){ //输出值为value的值1 alert(this.value); } //T:创建一个test方法的对象 var T=new test(); //获取id为a的文本框,输出值为1 document.getElementById('a').onclick=function(){ T.get(); } //获取id为b的文本框,取得文本框内的值为b document.getElementById('b').onclick=T.get; </script>
1402
马鹏磊
1518
Cracia
606
小浣熊
1458
梦紫菱0124
872
杨柳
847
Yc
第一个input点击出来的alert为1
第二个input点击出来的alert为b
1932
740317431
1902
王之神判
1694
wulinan
1135
zxx
762
sangpeng
360
付玲
741
lilin
651
hanqian
298
moon110
点a 弹1
点b 填b
站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.
GMT+8, , Processed in 0.195171 second(s), 9 queries .
Powered by javakc! X1.0
© 2004-2014 javakc
f1208.com 备案号:京ICP备14030918号-1