星期五, 八月 24, 2007

关于Javascript的this关键词的解释.

往往在函数中使用this关键词
function checkme()
{
alert(this.value);
}

此时this代表 是当前聚焦的可视HTML元素(focus element).比如一个下拉框,输入框等等。

最严密的说法如下:

http://www.quirksmode.org/js/this.html

In JavaScript this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of. When we define our faithful function doSomething() in a page, its owner is the page, or rather, the window object (or global object) of JavaScript. An onclick property, though, is owned by the HTML element it belongs to.