js this
来源:互联网 发布:手机看图纸软件 编辑:程序博客网 时间:2024/06/14 20:12
js 中的this指的是事件的产生对象。即getElementById的到的对象等一样。比如做一个鼠标移动到不同按钮面板切换效果通过鼠标停留到的span中的值来判断鼠标移动到哪里,应该在给span中添加的事件onmouseover()中传一个参数this。这样在js的onmouseover(obj)时间中接受这个对象参数,用obj.innerHTML来判断是滑过哪个span,如果添加事件时没有传参数this,那么这个函数里的this.innerHTML就得不到span中的值,因为此时的this指的是window而不是span。面板切换效果代码示例:html: <span OnMouseOver="action(this)">找<br/>西</span><br/><br/> <span OnMouseOver="action(this)">减<br/>肥</span><br/><br/> <span OnMouseOver="action(this)">发<br/>到</span>
js: function action(obj) { switch (obj.innerHTML) { case '找<br>西':span[53].style.background='red';span[54].style.background='gray';span[55].style.background='gray';div1.style.display='block'; div2.style.display='none';div3.style.display='none';break; case '减<br>肥':span[54].style.background='red';span[53].style.background='gray';span[55].style.background='gray';div2.style.display='block'; div1.style.display='none';div3.style.display='none';break; case '发<br>到':span[55].style.background='red';span[53].style.background='gray';span[54].style.background='gray';div3.style.display='block'; div2.style.display='none';div1.style.display='none';break; } }
0 0
- jquery&js $(this) & 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和$(this)区别
- 洗牌和发牌算法
- 修改自定义key store 别名和密码
- Num 39 : HDOJ : 2030 汉字统计 [ 汉字的字符处理 ] [ 转载 ]
- Android AIDL Service 跨进程传递复杂数据
- android:设置密码隐藏与显示
- js this
- IOS 笔记 《一》:内存管理
- Android AIDL Service 跨进程传递复杂数据
- jquery 获取本身HTML
- 获取OlapConnection连接
- 控制流
- Spark入门实战系列--6.SparkSQL(下)--Spark实战应用
- 使用 daemon()函数创建守护进程的用法,变为守护进程后程序每 60 秒打印当前的时间信息到/tmp/daemon.log 文件中
- 在SSH整合过程中ClassCastException:xxx_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy