<HTML>
<HEAD>
<TITLE>Example 5.3</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function calculate(form) {
form.results.value = eval(form.entry.value);
}
function getExpression(form) {
form.entry.blur();
form.entry.value = prompt("Please enter a JavaScript mathematical expression","");
calculate(form);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD=POST>
Enter a JavaScript mathematical expression:
<INPUT TYPE=text NAME="entry" VALUE="" onFocus="getExpression(this.form);">
<BR>
The result of this expression is:
<INPUT TYPE=text NAME="results" VALUE="" onFocus="this.blur();">
</FORM>
</BODY>
</HTML>
以上代码来自一个js教程。
问题:
onFocus="getExpression(this.form);"
,这里的 this
代表什么?我以为是window对象,如果是这样,那么就无法解释这一行:onFocus="this.blur();"
,或者两者都表示this
表示输入字段,如果是这样,如何使用 this.form
(input.form)?
我在这里对 'this'
感到困惑,有人能给我解释一下吗?谢谢。
最佳答案
onFocus="getExpression(this.form);" , what does this represent here?
this
这是您的输入 <INPUT TYPE=text NAME="entry"/>
onFocus="this.blur();"
this
这是您的输入 <INPUT TYPE=text NAME="results"/>
关于javascript - 与 js 中的一种形式的 'this' 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17290062/