a form in the eye
in the HTML , the form is made up of <form> element to represent, in the JavaScript The form corresponds to the htmlformelement type. The form we use is made up of the various controls in the form. Here's a look at its fields and operations.
second, the form introduces a few key points 1. Sequence of response ofBlur and change events in different browsers
There are no strict rules regarding the relationship between the Blur and the Change event. Blur events and Change events, one is the loss of focus, and the other is changing the options. in some browsers,theBlur event occurs before the Change event, whereas in other browsers, it is the opposite. For example:
<span style= "FONT-SIZE:14PX;" >addevent (window, ' Load ', function () { Varfm=document.getelementbyid (' myForm '); varuser=fm.elements[' user ']; Addevent (user, ' blur ', function () { alert (' blur '); }); Addevent (user, ' Change ', function () { alert (' Change '); });); </span>
different browsers will have different order of reaction. But most browsers still first change after Blur, small try IE, FireFox,Google,and360.
2. Submit a Form
The biggest problem with submitting data is repeating the form. For various reasons, When a data is submitted to the server, there will be a delay, and so on for a long time not reflected, Users think that the browser does not respond, or the speed of the problem, so that the user will not stop clicking Submit, so that repeatedly submitted a lot of the same request, or caused errors, or write more than one message to the database.
Let's do one first. 3 analog delay for seconds
<span style= "FONT-SIZE:14PX;" >ADDEVENT (FM, ' Submit ', function (evt) {//Analog delay Predef (EVT), setTimeout (function () {fm.submit ();}, 3000);}); </span>
There are two ways to solve this problem:
The first is after the submission, immediately disable the click button;
document.getElementById (' Sub '). disabled= true; Disable the button
The second is to cancel subsequent form submission operations after submission.
<span style= "FONT-SIZE:14PX;" >varflag = False//Set a listener variable if (flag = = true) return//If present returns Exit event flag = TRUE; Otherwise OK is the first time, set to True</span>
third, cross-browser processing
to implement selecting Some text in the input box in form, there is a compatibility problem with the browser, the solution:
<span style= "FONT-SIZE:14PX;" >//Select Partial text to implement cross-browser compatible functionselecttext (text, start, stop) { if (text.setselectionrange) { Text.setselectionrange (start,stop); Text.focus (); } else if (text.createtextrange) { var range =text.createtextrange (); Range.collapse (true); Range.movestart (' character ', start); Range.moveend (' character ', Stop-start); IE uses the endpoint minus the starting point to get the number of characters range.select ();} } </span>
Use Select event that can be triggered after the text box text is selected.
<span style= "FONT-SIZE:14PX;" >addevent (TextField, ' select ', function () { alert (this.value);//ie event needs to pass this to write});</span>
in JS The most headache is the browser compatibility problem, Li Tinghui teacher in the entire video explaining the process has been to solve the browser compatibility issues. But at the same time the teacher is also to convey to us a reason, when you test successfully under a browser, does not mean that all users will use this browser, if the user sees in another browser is completely another, or the function can not be implemented, this is the failure of our software. Therefore, the compatibility of the browser is also reflected in the purpose of serving the whole heart wholeheartedly.
JS Basic---form processing