JS built-in function Daquan and basic usage method (i)

Source: Internet
Author: User

One, general functions

Alert function : Displays a warning dialog box, including an OK button.

Syntax: alert ("Hello World");

Confirm function : Displays a confirmation dialog box, including OK, Cancel button.

Syntax: Confirm ("OK to remove xxx?"). ");

prompt function : Displays a dialog box with a text box prompting you to wait for user input.

Syntax: Prompt ("Please enter your user name", "show the default value of the text box here");

Two, String functions

connector ' + ': Connect two strings together

Syntax: Var str= ' a ' + ' B ';//Result: STR has a value of AB

substring function : Syntax 1: Intercept starting from the X-character
var str= "This is my test string";
var sub=str.substring (6);//Result: The value of sub is ' s my test string '

Syntax 2: Intercept characters from the X-bit to the Y-bit
var str= "This is my test string";
var sub=str.substring (0,6);//Result: The value of sub is ' this I '

Slice function : intercepts the characters from the X-position to the Y-position of the countdown
Grammar:
var str= ' This is my test string ';
var slc=str.slce (0,-2);//Result: The value of the SLC is the This is my test strin

substr function
Grammar:
var str= ' This is my test string ';
var subs=str.substr (2,6);//Result: The value of subs is ' I '

tolowercase function : Convert to lowercase

Grammar:
var myString = "Hello";
var lcstring = Mystring.tolowercase (); Result: "Hello"

touppercase function : Uppercase
Grammar:
var myString = "Hello";
var ucstring = Mystring.touppercase (); Result: "HELLO"
string comparisonvar astring = "Hello!"; var bstring = new String ("hello!"); if (astring = = "Hello!") {}//Result: true if (astring = = bstring) {}//Result: true if (astring = = = bstring) {}//Result: false (two objects different, although their values are the same)Retrieving Stringsvar myString = "Hello everybody.";//If the retrieval does not return to 1, the retrieved Word returns the start position in the string if (Mystring.indexof ("every") >-1) {}//Result: true   Find replacement string 
           var myString = "I am your father."  var result = Mystring.replace ("is", "AM");//Result: "I am your father."   special character : \b: Back character \ t: Horizontal tab \ n: newline character \v: Vertical tab \f: page break \ r: Carriage return \ ": double quotation mark \ ': single quote \ \: Backslash 
Three, string transcoding

converts characters to Unicode encoding var myString = "Hello" ; var code = mystring.charcodeat (3); Returns the Unicode encoding for "L" (integer) var char = String.fromCharCode (66);//Returns a Unicode 66 character converts a string to a URL-encoded var myString = "Hello all" ; var code = encodeURI (myString);//Result: "Hello%20all" var str = decodeURI (code);//Result: " Hello all "
corresponding
:
encodeURIComponent () decodeuricomponent () converts a string to base64 encoding /strong> Base64Encode () Base64decode () use ibid.

JS built-in function Daquan and basic usage method (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.