1.HTML 内のスクリプトは、<script> タグと </script> の間に配置する必要があります。
スクリプトは HTML ページの
セクションに配置できます2. JavaScript から HTML 要素にアクセスするには、 document.getElementById(id) メソッドを使用できます
3. document.write() を通じて、タグを含むコンテンツを HTML ドキュメントに書き込むことができます。ドキュメントがロードされた後に document.write() が実行されると、HTML ドキュメント全体が上書きされることに注意してください
4.JS は 2 つの方法でアノテーションを付けます: // と /**/
5. 変数は var を通じて宣言されます。JS は弱い型指定言語であるため、変数の型を指定する必要はありません。
7.var num=new Number()//Declare a Number object
Number.MAX_VALUE Maximum value
Number.MIN_VALUE Minimum value
Number.NaN special non-numeric value
Number.NEGATIVE_INFINITY Negative infinity
Number.POSITIVE_INFINITY Positive infinity
Number.toExponential() Format numbers using exponential notation
Number.toFixed( ) uses fixed-point counting to format numbers
Number.toLocaleString() Converts numbers into local format strings
Number.toPrecision() Format the significant digits of the number
Number.toString( ) Converts a number into a string
Number.valueOf( ) returns the original value
8.var str = new String() //Declare a string object
str.substr(start,length): Extract and return a substring in str. But it does not modify str. start indicates the starting position of extraction, and length indicates the length. If length is omitted, it indicates extraction to the end.
str.substring(from,to): will return the substring of the string string, consisting of the characters from from to to, including the characters located in from, excluding the characters located in to. If from>to, that is Intercepted after automatic replacement.
Str.toLowerCase(): Convert the string to lowercase
Str.toUpperCase(): Convert the string to uppercase
str.split(): Split the string according to the specified symbol
str.slice(): Same as substring() but more flexible, allowing negative values, similar to Array.slice()
str.concat(): String link, similar to Array.concat, but it is more convenient to use numbers
Str.indexOf(): Retrieve characters and return the position where the character first appears
9.var date=new Date() //Create a date object
Main methods:
Date.get/setDay() //Return/set a day of the week (0~6),
Date.get/setFullYear() // Return/set the year in system time
Date.get/setMonth() // Return/set the month field (0~11) in system time
date.get/setDate() //Return/set a certain day of the month
Date.get/setHours() // Return/set the hour field in the system time
Date.get/setMinutes() // Return/set the minutes field in the system time
Date.get/setSeconds() // Return/set the seconds field in the system time
Date.get/setTime() //Return/Set//Return/Set the minute field in the system time
10.var arr=new Array() //Create an array object
Main attributes: arr.length //Returns the length of the array
Main methods:
pop() //Delete and return the last element of the array, the return value is the deleted element
push() //Add elements to the end of the array and return the length of the array
shift() //Move the first element out of the array, and the return value is the deleted element
unshift() //Insert an element at the head of the array and return the length of the array
slice() //Return a part of the array, the parameter can be a negative value, return the intercepted array
Reverse() //Reverse the order in the array and return the reversed array
sort() //To sort array elements, you need to specify a method
concat() //Array connection, returns the connected array without changing the original array
join() //Join the array elements with the specified characters and return them in string form
splice() //Insert, delete or replace elements of the array,
toString() //Convert the array into a string
11.Math is a native object
Math.abs() //Return the absolute value
Math.ceil() // Round up
Math.floor() // Countryside rounding
Math.round() // Rounding up
Math.randow() // Returns a random number
Math.max() // Return the larger value
Math.min() // Return the smaller value
Math.PI() //Constant PI
Math.pow() // x to the y power
Math.sqrt() // Calculate the square
12. Others
isNaN() // Determine whether it is a numerical value. If not, return true
parseInt() // Forced conversion to integer type
parseFloat() // Forced conversion to floating point value
alert() // Warning
confirm() //Message confirmation box
prompt() //Prompt message box
Document.write() //Write content to the HTML document. If the document content is loaded and written using this method, the entire HTML document will be overwritten
document.getElementById() //Get the object by ID name
document.getElementsTagName() //Get the object through the tag name and return an array object
document.getElementsClassName() //Get the object through the class name and return an array object
The above is the entire content of this article, I hope you all like it.