js中this的用法

一、this指触发事件的对象
javascript

<input type="text" value="eye for eye" id="myeye">
<input id="myinput" type="text" value="javascript中onclick中的this" onclick="javascript:test(this);"/>

二、this在js中的使用
html

function test(obj){ 
alert(obj); //[object HTMLInputElement] 
alert(obj.id); //myinput 
alert(obj.value); //javascript中onclick中的this 
}

三、获取dom元素的上一个对象
java

alert($(obj).prev('input').val());//eye for eye
相关文章
相关标签/搜索