我對JS中'this'的用法感到困惑。從w3cshoolThis.value與值,有什麼不同?
採取例如: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onchange2
<!DOCTYPE html>
<html>
<body>
<p>Modify the text in the input field, then click outside the field to fire the onchange event.</p>
Enter some text: <input type="text" name="txt" value="Hello" onchange="myFunction(this.value)">
<script>
function myFunction(val) {
alert("The input value has changed. The new value is: " + val);
}
</script>
</body>
</html>
如果我刪除 '本',它的工作原理也一樣,太糟糕了,我不能找到任何w3school教程來區分它。
在這種情況下,'this'是否會與'this'不同?
https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work也許這會有所幫助。 – Abhijeet
+1給Abhijeet。作爲@Abhijeet建議的整體視圖,請參閱[本SO線程](https://stackoverflow.com/a/3127440/5909393)。 – Sidtharthan