The content of this article is to share with you 100 commonly used js functions and syntax, which has a certain reference value. Friends in need can refer to it
Website special effects are inseparable from scripts, and javascript is the most commonly used Scripting language, let’s summarize the commonly used basic functions and syntax:
1. Output statement: document.write("");
2. The comments in JS are //
3. The traditional HTML document sequence is: document->html->(head,body)
4. DOM in a browser window The order is: window->(navigator, screen, history, location, document)
5. Get the name and value of the element in the form: document.getElementById("The name and value of the element in the form ID number").name (or value)
6. A lowercase to uppercase JS: document.getElementById("output").value = document.getElementById("input").value. toUpperCase();
7. Value types in JS: String, Number, Boolean, Null, Object, Function
8. Convert character type to numeric type in JS: parseInt(),parseFloat()
9. Convert numbers in JS to character type: ("" variable)
10. Get the string length in JS: (length)
11. Characters in JS are connected with characters using symbols.
12. The comparison operators in JS are: == equal to, != not equal to, >, >=, <.<=
13. Use: var to declare variables in JS
14. Judgment statement structure in JS: if(condition){}else{}
15.JS Loop structure: for([initial exPRession];[condition];[upadte expression]) {inside loop}
16. The command to terminate the loop is: break
17. Function definition in JS: function functionName([ parameter],...){statement[s]}
18. When multiple forms appear in the file, you can use document.forms[0], document.forms[1] instead.
19 .Window: open the window window.open(), close a window: window.close(), the window itself: self
20. Status bar settings: window.status="character";
21. Pop-up prompt Information: window.alert("character");
22. Pop up the confirmation box: window.confirm();
23. Pop up the input prompt box: window.prompt();
24. Specify the current display Link location: window.location.href="URL"
25. Get the number of all forms in the form: document.forms.length
26. Close the document's output stream: document.close();
27. String append connector: =
28. Create a document element: document.createElement(), document.createTextNode()
29. Method to get the element: document.getElementById()
30. Set the values of all text members in the form to be empty:
var form = window.document.forms[0]for (var i = 0; i<form.elements.length;i++){ if (form.elements[i].type == "text"){ form.elements[i].value = ""; } }
31. Determine whether the check button is selected in JS: document.forms[0].checkThis.checked (the checked attribute represents whether it is selected and returns TRUE or FALSE)
32. Radio button group ( The names of the radio buttons must be the same): Take the length of the radio button group document.forms[0].groupName.length
33. The radio button group is also used to determine whether it is selected. checked.
34. Drop-down list Box value: document.forms[0].selectName.options[n].value (n sometimes uses the name of the drop-down list box plus .selectedIndex to determine the selected value)
35. Definition of string: var myString = new String("This is lightsWord");
36. Convert the string to uppercase: string.toUpperCase(); Convert the string to lowercase: string.toLowerCase();
37. Return string 2 in The position that appears in String 1: String1.indexOf("String2")!=-1 means it is not found.
38. Get a character at the specified position in the string: StringA.charAt(9);
39. Take out the substring of the specified starting point and end point in the string: stringA.substring(2,6);
40. Mathematical functions: Math.PI (returns pi), Math.SQRT2 (returns square root), Math .max(value1,value2) returns the highest value of the two numbers, Math.pow(value1,10) returns the tenth power of value1, Math.round(value1) rounding function, Math.floor(Math.random() *(n 1)) returns a random number
41. Define date type variable: var today = new Date();
42. Date function list:
dateObj.getTime() gets the time,
dateObj.getYear() gets the year,
dateObj.getFullYear() gets the four-digit year,
dateObj.getMonth() gets the month,
dateObj.getDate() gets the day,
dateObj.getDay () gets the date,
dateObj.getHours() gets the hours,
dateObj.getMinutes() gets the minutes,
dateObj.getSeconds() gets the seconds,
dateObj.setTime(value) sets the time ,
dateObj.setYear(val) sets the year,
dateObj.setMonth(val) sets the month,
dateObj.setDate(val) sets the day,
dateObj.setDay(val) sets the day of the week,
dateObj.setHours sets hours,
dateObj.setMinutes(val) sets minutes,
dateObj.setSeconds(val) sets seconds [Note: This date and time starts from 0]
43.FRAME Representation method:
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent represents the parent object, top represents the top object
45.Open The parent window of the child window is: opener
46. Indicates the current location: this
47. When calling a JS function in a hyperlink, use: (javascript:) to start with the function name
48 .Do not execute this JS in old browsers:
49. Reference a file-style JS:
50. Specify the HTML displayed in browsers that do not support scripts:
51. When there are both hyperlinks and ONCLICK events, then Older versions of browsers will redirect to a.html, otherwise they will redirect to b.html. Example: dfsadf52.JS’s built-in objects include: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
53.JS Line break in:\n
54. Window full screen size:
<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen. availHeight;}window.maximize=fullScreen;</script>
55.all in JS represents all the elements below it http://bizhi.knowsky.com/
56.Focus order in JS: document.getElementByid("Form Element").tabIndex = 1
57.The value of innerHTML is the value of the form element: such as
"how are you "
, then the value of innerHTML is: how are youThe above is the detailed content of 100 commonly used js functions and syntax. For more information, please follow other related articles on the PHP Chinese website!