Event = a function with parentheses gets the return value. event = a function without parentheses assigns the function itself to the event. event = "function with parentheses" indicates the execution function.
<HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <br/> <title> untitled document </title> <br/> <MCE: script language =" JavaScript "> <! -- </P> <p> function move () <br/> {<br/> var Top = 100 + document. body. scrolltop; <br/> document. getelementbyid ("adlayer "). style. pixeltop = top; <br/> return top; <br/>}< br/> window. onscroll = move; <br/> function showmove () <br/>{< br/> var movevalue = move (); <br/> alert (movevalue ); <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Div style = "height: 1900px; Background-color: black "> </div> <br/> <Div id =" adlayer "style =" position: absolute; top: 100px; left: 50px; Z-index: 2 "> <br/> <br/> <input type = "button" value = "button" onclick = "showmove () "> <br/> </div> <br/> </body> <br/> </ptml> <br/>
After reading this example, let's look at the following description:
First
VaR movevalue = move (); here we define the variable and assign the move () value to the variable. Then, the value obtained by movevalue is the retrun value returned after the move () function is executed.
Next
Window. onscroll = move; I want to clarify first that VaR move = function () {function content} is equivalent to function move () {function content}, that is, the variable move is the function itself. then we will try again window. onscroll = move to understand, we are assigning the "function itself" to the window event onscroll; that is
Onscroll indicates funtion move () {function content} instead of the value returned by the function;
Last
Onclick = "showmove ()" here is the event execution function. The event is not equal to or equal to the retrun value of the function. It only executes a function when the event is triggered.
Through comparison, we can easily understand the differences between the three. The function with event = parentheses gets the return value, and the function with event = Not parentheses assigns the function itself to the event, event = "function with parentheses" is the execution function
Another important point is that onclick = "showmove" is the HTML event mechanism, while var movevalue = mone () and window. onscroll = move are javscript.
Reference: http://www.zhaowenlong.com/post/2010/09/2.html