ArticleDirectory
- HTML Dom submit () method
- Description
- HTML Dom onsubmit event handle
- Syntax
- Description
Problem:
If you want to execute a JS function after opening the page, you can put it in the onload of the body. The format is as follows:
< Body onload = " BB () " >
However, for Javascript, the JavaScript code in the page is executed once before the page is loaded.Code, Class launch the following ideas:
The code between <SCRIPT> </SCRIPT> is executed. If the following method is used, alert () is automatically executed ();
< Script Type = " Text/JavaScript " > Alert ( 123 ); < / SCRIPT>
The executable function is also implemented as follows:
< Script Type = " Text/JavaScript " >
Function AA (){
Alert ("aaaaaa ");
}
Function BB (){
Alert ("bbbbbb ");
}
AA ();
</SCRIPT>
You can also execute the AA () function, but run this function before executing and loading the body. It must be earlier than BB () in the body. The execution result is AAAAA and bbbbbb. Test match.
In addition, you can use the following document. Write () method to execute the BB () function: the effect is the same as that of directly calling BB;
< Script Type = " Text/JavaScript " >
Document. Write ( ' <SCRIPT type = "text/JavaScript"> ' );
Document. Write ( " BB () " );
Document. Write ( ' <\/SCRIPT> ' );
< / SCRIPT>
Understanding: It is not clear about the JS running mechanism, so we can deepen our understanding, write more tests, summarize more, and take more notes.
In addition, the differences between submit and onsubmit are as follows:
HTML Dom submit () method
Http://www.w3school.com.cn/htmldom/met_form_submit.asp
Syntax
Formobject. Submit () Description This method submits a form in the same way as clicking the submit button, but the onsubmit event handle of the form is not called.
HTML Dom onsubmit event handle
Http://www.w3school.com.cn/htmldom/prop_form_onsubmit.asp definition and usage
The event handle called when the form is submitted.
Syntax Form. onsubmit Description
The onsubmit attribute of the form object specifies an event handle function.When you click the submit button in the form to submit a form, the event handle function is called.. Note,When the form. Submit () method is called, the processor function is not called.
IfThe onsubmit handle returns the fasle, and the elements in the form will not be submitted.. If this function returns other values or nothing, the form will be submitted.
Execution sequence of JavaScript during page loading
We recommend that you read this article:
Summary of JavaScript Execution Sequence