在JS中以一种形式与“this”混淆
got confused with 'this' in one form in js
<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
在这里代表什么?我以为是窗口对象,如果是这样,那么无法解释这行:onFocus="this.blur();"
,或者两者都this
表示输入字段,如果是这样,如何用户站立this.form
(input.form(?我对这里的'this'
感到困惑,谁能给我解释一下?谢谢。
onFocus="getExpression(this.form(;" ,这在这里代表什么?
this
这是您的输入<INPUT TYPE=text NAME="entry"/>
onFocus="this.blur((;">
this
这是您的输入<INPUT TYPE=text NAME="results"/>
this
表示它指的是那个特定的形式,那个特定的元素。
示例:这是我发布过的最短答案(指这个问题(
这个关键字在JS环境中是一个棘手的关键字 我会推荐这篇文章,因为它确实帮助我前段时间理解了它。了解此关键字。
在这种情况下,如果函数不是由 call(( 或 apply(( 执行的,它修改了 this 关键字的行为,它应该表示函数的调用者,在这种情况下是触发事件的输入。
希望这对:)有所帮助
相关文章:
- $(this).prop('property') vs. this.property
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 在另一个函数中使用变量this
- this.router在AngularJS 2中未定义
- reactjs this.refs vs document.getElementById
- JavaScript 中的嵌套函数和 “this” 关键字
- React+Meteor:this.ops返回未定义
- javascript中对象构造函数中的var属性与this.properties
- 函数中this和var之间的区别
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- 将错误与if语句混淆
- Understanding Javascript scope with "var that = this&qu
- 定义this.properties或objectName.properties的javascript JSON对象
- Object.prototype using 'this'
- 在JavaScript类型的函数中避免self-this
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- 与 JavaScript 代码中的“this”混淆
- 将 this.el 与主干.js子视图混淆
- 在JS中以一种形式与“this”混淆
- 在Javascript中,与"this"混淆如何让这个_this_when方法被事件调用?