Home Web Front-end JS Tutorial Some things you must know to learn js_Basic knowledge

Some things you must know to learn js_Basic knowledge

May 16, 2016 pm 07:18 PM

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 order 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 of the element in the form No.").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. Numbers in JS Convert to character type: ("" variable)
10. The length of string in JS is: (length)
11. Characters in JS are connected with characters using numbers.
12. In JS The comparison operators are: == equal to, != not equal to, >, >=, <.>13. Use: var to declare variables in JS
14. Judgment statement structure in JS :if(condition){}else{}
15. Loop structure in JS: for([initial expression];[condition];[upadte expression]) {inside loop}
16. Loop abort command Yes: 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 window window.open(), close a window: window.close(), window itself: self
20. Status bar Settings: window.status="character";
21. Pop-up prompt message: window.alert("character");
22. Pop-up confirmation box: window.confirm();
23. Pop-up 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 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 value of all text members in the form to empty:
var form = window.document.forms[0]
for (var i = 0; i if (form.elements.type == "text"){
form.elements.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 (radio button The names must be the same): take 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 (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 string to uppercase: string.toUpperCase(); Convert string to lowercase: string.toLowerCase();
37. Return string 2 in string 1 The position that appears in: 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 it out Substring specifying the 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)) Return random numbers
41. Define date variables: var today = new Date();
42. List of date functions: 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() Get points, dateObj.getSeconds() gets 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 the hours, dateObj.setMinutes(val) sets the minutes, dateObj.setSeconds(val) sets the 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 of the child window The window is: opener
46. Indicates the current location: this
47. When calling a JS function in a hyperlink, use: (javascript:) to start and add the function name
48. In the old This JS is not executed in the browser:
49. Quote a file-style JS:

51. When there are both hyperlinks and onCLICK events, the old version of the browser will turn to a.html, otherwise it will turn to b.html. Example: dfsadf

52.JS’s built-in objects are :Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object, RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53. Line break in JS: n
54. Window full screen Size:

55.all in JS represents all elements below it

56.Focus order in JS: document.getElementByid("Form Element").tabIndex = 1 57.innerHTML The value is the value of the form element: such as "how are

you<script></script>"<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>, then the value of innerHTML is: how are you
58. The value of innerTEXT is the same as above, except that the tag will not be displayed.
59.contentEditable can Set whether the element can be modified, isContentEditable returns the status of whether it can be modified.
60.isDisabled determines whether it is a prohibited state. disabled sets the prohibited state
61.length gets the length and returns an integer value
62.addBehavior () is an external function file called by JS. Its extension is .htc
63.window.focus() puts the current window in front of all windows.
64.blur() means losing focus. With FOCUS () on the contrary.
65.select() means that the element is selected.
66. Prevent the user from entering text in the text box: onfocus="this.blur()"
67. Remove the element in Number of occurrences in the page: document.all.tags("div (or other HTML tags)").length
68. There are two types of form output in JS: modal and non-modal.window.showModaldialog (), window.showModeless()
69. Status bar text setting: window.status='text', default status bar text setting: window.defaultStatus = 'text.';
70. Add to Favorites: external.AddFavorite("http://www.dannyg.com";,"jaskdlf");
71. No action is taken when a script error is encountered in JS: window.onerror = doNothing; Specify the error The syntax of the handle is: window.onerror = handleError;
72.JS specifies the parent window of the currently opened window: window.opener, which supports multiple continuations of opener.opener....
73.self in JS Refers to the current window
74. The status bar display content in JS: window.status="content"
75. Top in JS refers to the top-level frame in the frame set
76. In JS Close the current window: window.close();
77. Confirm box in JS: if(confirm("Are you sure?")){alert("ok");}else{alert(" Not Ok");}
78.Window redirection in JS: window.navigate("http://www.sina.com.cn";);
79.Print in JS: window. print()
Prompt input box in 80.JS: window.prompt("message","defaultReply");
Window scroll bar in 81.JS: window.scroll(x,y)
82.Scroll the window to the position in JS: window.scrollby
83. Set the time interval in JS: setInterval("expr",msecDelay) or setInterval(funcRef,msecDelay) or setTimeout
84.JS The modal display works in IE4, but not in NN: showModalDialog("URL"[,arguments][,features]);
The handle used before exiting in 85.JS: function verifyClose(){event.returnValue= "we really like you and hope you will stay longer.";}} window.onbeforeunload=verifyClose;
86. The file handle used when the form is called for the first time: onload()
87. When the window File handle called when the body is closed: onunload()
Properties of 88.window.location: protocol(http:), hostname(www.example.com), port(80), host(www.example.com: 80), pathname("/a/a.html"), hash("#giantGizmo", refers to jumping to the corresponding anchor), href (all information)
89.window.location.reload() Refresh the current page.
90.window.history.back() returns to the previous page, window.history.forward() returns to the next page, window.history.go (returns to the first page, you can also use the visited URL)
91.document.write() output without line wrapping, document.writeln() output with line wrapping
92.document.body.noWrap=true; prevent link text from wrapping.
93. Variable name .charAt(number), get the character of the variable.
94."abc".charCodeAt(number), return the ASCii code value of the character.
95.Character String connection: string.concat(string2), or use = to connect
96. Variable.indexOf("character", starting position), returns the first occurrence position (calculated from 0)
97 .string.lastIndexOf(searchString[,startIndex]) The last occurrence of the position.
98.string.match(regExpression), determine whether the characters match.
99.string.replace(regExpression,replaceString) replace the existing String.
100.string.split (separator) returns an array storage value.
101.string.substr(start[,length]) takes the string from the number to the specified length.
102.string.toLowerCase() changes all characters to lowercase.
103.string.toUpperCase() changes all characters to uppercase.
104.parseInt(string[,radix(representing base)] ) is forced to be converted to an integer type.
105.parseFloat(string[,radix]) is forced to be converted to a floating point type.
106.isNaN (variable): Test whether it is a numeric type.
107. Define constants Keyword: const, keyword for defining variables: var

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript and the Web: Core Functionality and Use Cases JavaScript and the Web: Core Functionality and Use Cases Apr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript in Action: Real-World Examples and Projects JavaScript in Action: Real-World Examples and Projects Apr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding the JavaScript Engine: Implementation Details Understanding the JavaScript Engine: Implementation Details Apr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: Community, Libraries, and Resources Python vs. JavaScript: Community, Libraries, and Resources Apr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Python vs. JavaScript: Development Environments and Tools Python vs. JavaScript: Development Environments and Tools Apr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

See all articles