JavaScript: 006-JS Function Definition, JS
JS function declaration.
The declaration function format is as follows:
Function Name (parameter list) {// function statement; return value ;}
Let's look at the specific function declaration.
1. Common functions
<Script type = "text/javascript"> function ShowHint () {alert ("common function") ;}</script>
2. Functions with Parameters
<Script type = "text/javascript"> function ShowResult (obj) {// processing statement return false; // return true ;}</script>
Note that for JS functions that generate callback controls such as buttons, the return false is added at the end of the function. If you use return false for some simple operations on the page or just call the JS function of a method in the background, you can avoid frequent page refreshes.
3. Return Value Function
<script type="text/javascript"> function ShowReturnObject() { Object obj = new Object(); return obj; }</script>
Returns a JS object.
JavaScript Functions are not complex, but you must note that braces must appear in pairs when writing them. Once a place is missing, troubleshooting is quite difficult for JavaScript code with hundreds or thousands of lines.
Javascript is simple and easy to use, but it is easy to write errors in syntax and difficult to find. Presumably most programmers really love and hate it...
How does javascript call custom functions on other JS pages?
Let me give you an example.
One way is to directly call
<Script> aa (); </script>
There are also some event calls
<A href = '# 'onclick = 'aa ()'> aa </a>
For more information, see the basics .....
How can I directly use javascript function libraries without introducing them? How can I check functions provided by js?
The js function library you mentioned refers to the built-in js objects and methods. Since it is built-in, it is implemented by default by js. As for what you have to learn, for example, the commonly used String, Date, Math, RegExp, and other objects, and Dom objects. To understand JavaScript, we should start with these basic elements.