If the function name is "alt", I get the error: "alt is not a function". All other names work. Here is the code:
<!DOCTYPE HTML> <html> <head> </head> <body> <input type="button" value="click me" onclick="alt('dato',28);"/> <script type="text/javascript"> window.onload = function(){ alt = function(name,age){ alert(name + " " + age); } } </script> </body> </html>
Please change the name of the function from "alt" to whatever is allowed to see that it works.
Can anyone explain what is happening?
, , , onclick this . alt - , , alt HTML ( alt input, ).
onclick
this
alt
input
, alt window.alt, script, element alt, .
window.alt
, onclick="alt('dato',28);", : onclick="this.alt('dato',28);".
onclick="alt('dato',28);"
onclick="this.alt('dato',28);"
alt, , alt, HTML, , :
onclick="window.alt('dato',28);"
, , , window.alt HTMLInputElement.prototype.alt
HTMLInputElement.prototype.alt
10 :
H , Scope NewObjectEnvironment (, ).H Window object : - .null, Scope NewObjectEnvironment ( , ).NULL, Scope NewObjectEnvironment (element, Scope).: NewObjectEnvironment() ECMAScript 5 10.2.2.3 NewObjectEnvironment (O, E)
H , Scope NewObjectEnvironment (, ).
H Window object : - .
Window
null, Scope NewObjectEnvironment ( , ).
NULL, Scope NewObjectEnvironment (element, Scope).
: NewObjectEnvironment() ECMAScript 5 10.2.2.3 NewObjectEnvironment (O, E)
, .
function alt__(name,age){ alert(name + " " + age); }
<input type="button" value="click me" onclick="alt__('dato',28)" />
window.alt (, Window ):
<input type="button" value="click me" onclick="window.alt('dato',28)" />
function alt(name,age){ alert(name + " " + age); }
IDL content 1:
theInput.onclick = function(){ alt('dato',28); });
function alt(name,age){ alert(name + " " + age); } document.querySelector('input').onclick = function(){ alt('dato',28); };
<input type="button" value="click me" />
:
theInput.addEventListener('click', function(){ alt('dato',28); });
function alt(name,age){ alert(name + " " + age); } document.querySelector('input') ---------- .addEventListener('click', function(){ alt('dato',28); });
You cannot use html attribute names as functions in attribute values because it refers to the attribute value.
eg
<input type="button" value="click me" onclick="console.log(value)" />
there will be a console magazine "click me"
"click me"
http://jsfiddle.net/z45dbxL4/
Implied this. Same as
<input type="button" value="click me" onclick="console.log(this.value)" />
Source: https://habr.com/ru/post/1610123/More articles:webkit-overflow-scrolling hides the absolute position of the div - cssScapy installation on Mac: "ImportError: no module named pcapy" - pythonAssign a reference to an object, not an object - oopIs it possible to rotate UIAlertController (and Alert) in landscape orientation? - iosReactJs + Babel - defining components using separate files - javascriptПочему фоновый цвет мигает вместо плавного изменения? - javascriptPython 2.7: simple "for" loop implementation - pythonHouse Drawing Using java (console) - javaThe smallest n numbers from the list - pythonUnderstanding Python lambdas - pythonAll Articles