Commonly used attribute methods in JavaScript include: 1. The comment in JS is [//]; 2. Convert character type to numeric type [parseInt()]; 3. Get the length of the string [length]; 4. Use var to declare variables; 5. Judgment statement structure [if(condition){}else{}].
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Commonly used attribute methods in JavaScript are:
1.document.write(""); Output statement
2. The comment in JS is/ /
3. The traditional HTML document sequence is: document->;html->(head,body)
4. The DOM sequence in a browser window is: window ->;(navigator,screen,history,location,document)
5. Get the name and value of the element in the form: document.getElementById("ID number of the element in the form").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 types into numerical types in JS: parseInt(), parseFloat()
9. Convert numbers in JS to character type: ("" variable)
10. Get the string length in JS: (length)
11.JS Characters are connected with characters using numbers.
12. The comparison operators in JS are: ==Equal,!=Not equal,>;,>;=,<.<=
13. Use var to declare variables in JS.
14. Judgment statement structure in JS: if(condition){}else{}
15.JS The loop structure in: for([initial expression];[condition];[upadte expression]) {inside loop}
16. The command to terminate the loop is: break
17. In JS Function definition: function functionName([parameter],...){statement[s]}
18. When multiple form 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 Setting: window.status="Character";
21. Pop-up prompt message: window.alert("Character");
22. Pop-up confirmation box: window.confirm();
23. Pop up the input prompt box: window.prompt();
24. Specify the location of the currently displayed link: window.location.href="URL"
25. Get the number of all forms in the form: document.forms.length
26. Close the output stream of the document: document.close();
27. String append connector: =
28. Create a document element: document.createElement(),document.createTextNode()
29. Get the element method: document.getElementById()
30. Set the value of all text members in the form to empty:
var form = window.document.forms[0] for (var i = 0; i<form.elements.length;i ){ if (form.elements.type == "text"){ form.elements.value = ""; } }
31. Determine whether the check button is checked 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):
Get the length of the radio button group document.forms[0].groupName.length
33. Checked is also used to determine whether the radio button group is selected.
34. The value of the drop-down list box:
document.forms[0].selectName.options[n].value
(nSometimes the name of the drop-down list box plus .selectedIndex is used to determine Determine the selected value)
35. Definition of string: var myString = new String("This is lightsword");
36. Convert string to uppercase: string.toUpperCase( ); Convert the string to lowercase: string.toLowerCase();
37. Return the position where string 2 appears in string 1: String1.indexOf("String2")!=-1 means there is no Find.
38. Get a character at the specified position in the string: StringA.charAt(9);
39. Get the substring with the specified starting point and end point in the string: stringA. substring(2,6);
40. Math functions:
Math.PI (returns pi), Math.SQRT2 (returns square root), Math.max(value1, value2) returns The
of the two numbers is the most valuable, 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 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 seconds,
dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,
dateObj.setMonth(val)设置月,dateObj.setDate(val)设置日,
dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]
43.FRAME的表示方式:
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent代表父亲对象,top代表最顶端对象
45.打开子窗口的父窗口为:opener
46.表示当前所属的位置:this
47.当在超链接中调用JS函数时用:(javascript :)来开头后面加函数名
48.在老的浏览器中不执行此JS:;
49.引用一个文件式的JS:;
50.指定在不支持脚本的浏览器显示的HTML: