There are several ways to reference JavaScript in web pages:
1. Internal JavaScript files
<script> document.write("初始 JavaScript"); document.write("<h1>Hello,JavaScript</h1>"); </script>
It is to directly use the <script> tag to add JavaScript code to the HTML document
2. Using external JavaScript files
<script type="text/javascript" src="js/text.js"> </script>
It is to write the JavaScript code into an external file, save it with the extension *.js, and then assign the file to the src attribute in the <script> tag
3. Directly in HTML tags
<input name="submit" type="button" value="submit" onclick="javascript:alert('欢迎您')">
variable declaration
In JavaScript, variables are declared using var
var is a legal variable name;
type of data
Commonly used basic data types are:
undefined (undefined type) null (null type) number (numeric type) String (string type) bollean (boolean type)
Commonly used input/output
1. Warning (alert)
alert("Alert message");
2. Prompt
The prompt() method will pop up a dialog
prompt("Prompt information","Default information of the input box");
Common system functions
1.parseInt()
The parseInt() function parses as a string and returns an integer
parseInt("string");
2.parseFloat()
The parseFloat() function can parse a string and return a floating point number
parseFloat("string");
3.isNaN()
The isNaN() function is used to check if its parameter is a non-number and returns false if it is a number and returns true if it is not a number
isNaN(x);
custom function
function function name (parameter 1, parameter 2, parameter 3...) { //JavaScript statement;
[return return value] }