What makes a "return" to "return MyFunction ()"

The Moz Dev network provides an example of using onchanged as follows:

<textbox id="find-text" onchange="return myFunction(event);"/>

What is the difference between the above and below that does not use a “refund”?

<textbox id="find-text" onchange="myFunction(event);"/>

Here is a complete example:

<input onchange="return checkChanged()" type="checkbox" />
<script>
    function checkChanged() {
        alert("checkChanged");
        return false;
    }
</script>

Whether I use “return” or not, the value always changes after clicking. I would think that since it returns false, it will not allow the user to check the box.

EDIT: The actual answer in this example is Nothing. However, this is because onchange is not canceled. Other events, such as onclick ARE cancelable, and false return prevent the default action, for example, preventing a click from occurring (i.e., Validation will not change.)

+4
source share
3

myFunction(). , , <textarea>.

Function MDN onchange.

+2

- , . , , . , :

function multiply(num1, num2) {
return num1 * num2;
}
result = multiply(2, 4);

multiply . , . , ( 2 4) , result = 8;

return true false , , , javascript .

0

, , . , , , . , onclick ( onclick ) , .

Using a return value is to prevent the default event handler from executing based on the return value of the Boolean. Not every event can be undone. You can use return when you want, when you want in some state you want to prevent the execution of the default event.
For example: onclick event of the submit button of the form, if you return false, this will prevent the form from being submitted, and if you return true, it will continue to send from.

0
source

Source: https://habr.com/ru/post/1524703/


All Articles