web.js.this详解
来源:互联网 发布:js dom编程艺术 pdf 编辑:程序博客网 时间:2024/06/05 19:26
用this,记住一点,当前的方法属于谁,this就表示谁!!!!
看如下例子
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>输出空格</title> </head> <script type="text/javascript"> window.onload=function(){ var a=[1,2]; var obnt=document.getElementById('bnt'); a.b=5; a.Show=function(){ alert(this.b) } obnt.onclick=function(){ alert(this.value) } a.Show(); } </script> <body> <input type="button" name="bnt" id="bnt" value="你好" /> </body></html>
第一个是自己定义的show方法,show属于a,所以this就表示a;
即弹出(a.b=5)5。
第二个.onclick方法,它属于obnt,所以this就表示obnt,
即obnt.value
0 0
- web.js.this详解
- js中的this详解
- JS this关键字详解
- js中的this详解
- js this 函数详解
- js中的this详解
- js中this详解
- JS中的this用法详解
- js中的this关键字详解
- 详解js中的this用法
- js中的this关键字详解
- js this的指向详解
- js中的this关键字详解
- js中的this关键字详解
- JS 中 this 关键字详解
- JS 中 this 关键字详解
- JS中的this指针详解
- JS中的this对象详解
- [神经网络与深度学习][计算机视觉]SSD编译时遇到了json_parser_read.hpp:257:264: error: ‘type name’ declared as function ret
- 1016. 部分A+B (15)
- #1015 : KMP算法 裸kmp
- 服务器--使用WordPress搭建个人博客
- C语言补充学习
- web.js.this详解
- 1017. A除以B (20)
- System Verilog视频学习笔记(9)- Inheritance
- jQuery的属性与样式
- 小白题解 Codeforces 794B Cutting Carrot
- 数塔问题
- ubuntu mongoDB的一些相关基本操作
- 1018. 锤子剪刀布 (20)
- 判断一个整数转换成二进制后1的个数