I. Basic Library of functions
Split (): Used to split a string into a string array
toUpperCase ():
SUBSTR ():
Length
Length ()
splicing (two kinds)
+
Concat (): Merges multiple strings and returns the results of the merge
Find
The IndexOf () method returns the position of the first occurrence of a specified string value in a string
LastIndexOf (): Returns the last occurrence of a specified string value, in a string at the specified position from the back to the forward search
Delete/Add
Shift (): Used to remove the first element of the array and return the value of the first element
Pop (): Used to delete and return the last element of an array
Unshift (): You can add one or more elements to the beginning of the array and return the new length
Push (): You can add one or more elements to the end of the array and return the new length
Intercept
SUBSTR (start,end): Extracts a specified number of characters from the start subscript in a string
Simple example:
<script type= "Text/javascript" >var str= "I like PHP";//split to get each word var arr=str.split ("");//iterate over the array, get the first letter, uppercase, Put back in place var word= ""; var nstr= ""; for (var k in arr) {word=arr[k][0].touppercase () +arr[k].substr (1); nstr+=word+ "";} document.write (NSTR);</script>
To detect what the browser is:
<script type= "Text/javascript" >if (Navigator.userAgent.toLowerCase (). IndexOf ("MSIE") >=0) {document.write ("ie");} else if (Navigator.userAgent.toLowerCase (). IndexOf (' Firefox ') >=0) {document.write ("Huohu");} else if (Navigator.userAgent.toLowerCase (). IndexOf (' Chrome ') >=0) {document.write (' Google ');} </script>
A small example of a timer (review some basic functions):
Date ()
SetInterval ()
Getinterval ()
toLocaleString ()
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Get URL Address:
Parse the following URL:
Http://www.xxx:8080/test.php?user=admin&pwd=admin#login
- Location.href: Get the complete URL as above
- Location.protocol: Get the Transport protocol http:
- Location.host: Get host name together with Port www.xxx.cn:8080
- Location.hostname: Get host name www.xxx.cn
- Location.pathname: Get the host after part does not include the question mark? The latter part of the/test.php
- Location.search: Get the question mark in the URL, then the part before the pound #? user=admin&pwd=admin
- Location.hash: Get the part before # #login
<script type= "Text/javascript" >document.write ("href:" +location.href+ "<br/>");
Set the current host name and port number document.write ("Host:" +location.host+ "<br/>");d ocument.write ("Pathname:" +location.pathname + "<br/>");d ocument.write ("Search:" +location.search+ "<br/>");d ocument.write ("Hash:" +location.hash+ " <br/> location.replace ("http://www.baidu.com");</script>
JS Object-oriented: http://www.dreamdu.com/javascript/define_object/
Built-in functions in JavaScript