JavaScript string
A string is an array of characters, but in JavaScript the string is immutable: You can access text anywhere in the string, but JavaScript does not provide a way to modify the contents of a known string
Common features:
obj.length length obj.trim () Remove Blank obj.trimleft () obj.trimright) Obj.charat (n) Returns the nth character in a string Obj.concat (value, ...) Stitching Obj.indexof ( Substring,start) Sub-sequence position obj.lastindexof (Substring,start) Sub-sequence position obj.substring (from, to) get sub-sequence Obj.slice (Start, end) based on index     &NBsp; slicing obj.tolowercase () Capital Obj.touppercase () lowercase obj.split (delimiter, limit) split Obj.search (regexp) match from the beginning to return the first position where the match succeeded (G invalid) Obj.match (regexp) Global Search, If there is a G in the regular to find all, then only the first one is found. Obj.replace (regexp, replacement) Replace, there is g in the regular replaces all, otherwise only the first match is replaced, $ number: matches the nth group content; $& : Currently matching content; $ ': Text on the left side of the matched substring; $ ': Text on the right side of the matching substring $$: Direct Volume $ symbol
Boolean Type (Boolean)
The Boolean type contains only true and false, unlike Python, with its first letter lowercase (true/false)
= = Compare Values equal
For example:
1== ' 1 ' true
! = does not equal
For example:
1!=2true
= = = Comparison value and type are equal
1 = = = "1"
For example:
False1 = = 1true
!=== Not equal to
|| Or
&& and
Array
Arrays in JavaScript are similar to the list of Python
Size of obj.length array obj.push (ele) Trailing append element Obj.pop () Tail Gets an element Obj.unshift (ele) head Insert Element Obj.shift () Head remove element obj.splice (start, deletecount, value, ...) inserting, deleting, or replacing elements of an array obj.splice (n,0,val) Specify position insert element obj.splice (n,1,val) Specify position substitution element obj.splice (n,1) Specify location Delete element Obj.slice ( ) slicing Obj.reverse ( ) Invert Obj.join (Sep) concatenate array elements to build a string Obj.concat ( Val,..) connecting Arrays Obj.sort ( ) sorting on array elements
JavaScript defines variables:
Global variables:
name = "ABC"
Local variables
var name = "CBA"
To define a function:
<script> function function_name () {statement1; Statement2}</script>
Call Function:
Function_name ()
example: Define and invoke a function:
<! doctype html>
SetInterval (' func () ', interval) is a JavaScript timer that represents interval milliseconds per interval, executing the func () function once
CharAt (N): A method of JavaScript string: Gets the character that specifies the subscript, as with Python, with the subscript starting from 0
SUBSTRING (m,n): A method of JavaScript string that gets the character set from subscript m to nth subscript
Length:javascript a method of a string to get the length of a string
JavaScript for Loop
1, loop element is index
A=[11,22,33,44]for (var i in a) {Console.log (a[i]);} 11223344
Circular Dictionary
a={' name ': ' Zeng ', ' Age ': 28}for (var item in a) {Console.log (A[item]); } "Zeng" 28a={"name": "Zeng", "Age": 28}for (Var item in a) {Console.log (item); }nameage
2, loop, loop element subscript, does not support the dictionary
A=[11,22,33,44]for (var i=0;i<a.length;i=i+1) {Console.log (a[i]);} 11223344
JavaScript conditional judgment
if (condition) {
}else if (condition) {
}else if (condition) {
}else{
}
JavaScript DOM Operations :
1. Find the Label
A, directly looking for labels
document.getElementById (' id '): Get a single element document.getelementbytagname (' div ') by ID: Get multiple elements via tag Document.getelementbyclassname (' cl '): Get multiple elements from class
B, indirect search for labels
parentelement//parent node tag element children//All Word tags firstelementchild//First Sub-tab Element Lastelementchild//Last child tag element nextelementsibling//Next sibling tag element previouselementsibling Previous sibling tag element
2. Operation label
Get the text content in a label
A
tags. innerText
Re-assign a value to a label's inner text
Label. innertext= ""
<a>asdfa</a><a>8908</a><a>asd234</a>//get all a tags and save them to the LL list, Then use the For loop to modify the text content of all the A labels. Ll=document.getelementsbytagname (' a ') [A, A, a]for (Var i=0;i<ll.length;i=i+1) {ll[i].innertext= ' 666 '} "666"
B
ClassName Tag.classname = "" Direct overall operation Tag.classList.add ("style name") Add Style Tag.classList.remove ("style name") Delete style
Example: Select all, Reverse, cancel
<! doctype html>
This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1918963
The definition function of the JavaScript base