1. For the return value problem, once a return value exists in the function, the following statement is not executed and the return value directly jumps to the place where the function is called. The following PHP Functions Code If the first if condition matches, the function value returns the Boolean false value, which can return the value of a function and jump out of the function. If a return statement is encountered, Program In that line of code, the execution control will immediately return to the code that calls the program. Function
Copy code The Code is as follows: function chkinput (form)
{
If (Form. Title. value = "")
{
Alert ("Enter Article Title! ");
Form. Title. Select ();
Return false;
}
If (Form. content. value = "")
{
Alert ("the text cannot be blank @!! ");
Form. content. Select ();
Return false;
}
Return true;
}
2. When will the onsubmit event be triggered when the onsubmit attribute of form is triggered? The onsubmit event occurs when the confirmation button in the form is clicked. The reasons for not triggering are as follows:
A. The onsubmit attribute will be triggered only when the form uses a button such as input: Submit to submit. Otherwise, it will not be triggered. If a common input: button is used, a JavaScript function is specified in the onclick attribute. In this function, the submit () function of form is executed instead of the onsubmit attribute.
B. First read a piece of code:
Copy code The Code is as follows: <form action = "index. jsp" method = "Post" onsubmit = "submittest ();">
<Input value = "www">
<Input type = "Submit" value = "Submit">
</Form>
<Script language = "JavaScript">
<! --
Function submittest (){
// Some logic determines return false;
}
// --> </SCRIPT>
Click the submit button. This form is not submitted. One of them should be changed to the following code:
<Form action = "index. JSP "method =" Post "onsubmit =" Return submittest (); "> the original onsubmit attribute is like a method name of the <form> HTML object, and its value (a string) is the method body, and true is returned by default;
Like java, you can write any number of statements in the method body, including built-in functions and custom functions.
Although submittest () returns false, we only execute this function and do not process the result.
Onsubmit = "Return submittest () uses its return value to achieve the expected results. 3. The event handler function returns false. In most cases, false is returned for the event handler function, which can prevent default event behavior.
For example, if you click a <A> element by default, the page will jump to the page specified by the href attribute of the element. Return false is equivalent to the Terminator, and return true is equivalent to the executable. In JS, return false is generally used to cancel the default action. For example, when you click a link, in addition to triggering your onclick time (if you specify it), you also need to trigger a default event that is to execute the page Jump. So if you want to cancel the default action of an object, you can return false. Return false: <body> 1, <a href = "/" mce_href = "/" onclick = 'test (); '> hyperlink </a> 2, <input type = "button" onclick = 'test ()' value = "Submit"> 3, <form name = "form1" onsubmit = "return test ();"> content <input type = "Submit" value = "Submit"> </form> </body>
<Input type = "Submit" onclick = "submitaction (); Return false;"/> the submitaction method contains an action to submit a form. If return false is not added,
After the submitaction is executed, the submit button continues to execute its default event and submits the form again. This may be the root cause of many errors. Indeed, return false does not prevent the event from spreading to the top-level element, but prevents the browser from handling the event by default. You can try this way: first, comment out all JS scripts, and drag a piece in IE browser. You will find that the mouse will become a forbidden style, and the picture will be not dragged, it is the default behavior provided by the browser for the mousemove event.
Return false is to remove this behavior, otherwise the interrupted event you described will be executed continuously. In addition, the statement equivalent to return false is:
Window. event. returnvalue = false,
You can replace return false with this statement for verification. Finally, this method is only applicable to IE browsers.
In JS, return false is generally used to cancel the default action. For example, when you click a link, in addition to triggering your onclick time (if you specify it), you also need to trigger a default event that is to execute the page Jump. So if you want to cancel the default action of an object, you can return false. Return false:
<Form name = "form1" onsubmit = "Return youfunction ();"> ...... </form> <a href = "www. ***. com "onclick = "...; return false; "> dddd </a>