“自我”是什么意思是在javascript? [英] What does "self" mean in javascript?
问题描述
我读了这里, self指当前窗口或窗体。
在这种情况下,自我似乎没有引用现在的表单:
Self does not seem to refer to the current form in this case:
<form><input type="text" onkeyup="alert(self.foo.value)" name="foo"></form>
但是在这种情况下,它可以工作(指的是窗口):
However in this case it works (referring to the window):
<form><input type="text" onkeyup="alert(self.document.forms[0].foo.value)" name="foo"></form>
那么你什么时候使用 self
DOM财产超过窗口
?
So when would you use the self
DOM property over just window
?
推荐答案
对于所有窗口,
自己
和窗口
窗口的属性
对象是
当前窗口的同义词,
您可以选择使用它们将
引用到当前窗口。例如,
可以通过
关闭当前窗口,调用
窗口 c
code>或close self
。您可以使用这些
属性使您的代码更加
可读,或者从$ b $中消除
属性引用self.status
b表格称为状态
。
For all windows, the
self
andwindow
properties of awindow
object are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling theclose
method of eitherwindow
orself
. You can use these properties to make your code more readable or to disambiguate the property referenceself.status
from a form calledstatus
.
这篇关于“自我”是什么意思是在javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!