“自我”是什么意思是在javascript? [英] What does "self" mean in javascript?

查看:148
本文介绍了“自我”是什么意思是在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 close code>或 self 。您可以使用这些
属性使您的代码更加
可读,或者从$ b $中消除
属性引用 self.status b表格称为状态

For all windows, the self and window properties of a window 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 the close method of either window or self. You can use these properties to make your code more readable or to disambiguate the property reference self.status from a form called status.

这篇关于“自我”是什么意思是在javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆