Summary of common js Methods

Source: Internet
Author: User

Val (), append (), get (), split (), substr (), each (), html (), keyup (), trim (), show (), hide (), indexOf ()
One by one:
Val (): To evaluate and assign values to a page element.
Value: var result = $ ("# txtSearch"). val ();
Value assignment: $ ("# txtSearch"). val (result );

Each (): calls the following methods for Each element in a set for operations on a set, for example:
$. Each (data. list, function (I, item ){
Alert (item ["WikiTitle"] "+" item ["WikiID"]); // I is the following table of elements in the set. item represents the element itself.
});

Append (): Append an element to the specified page Element
For example, a list element <li> test! </Li>. Page elements like this can be dynamically added using the append method. For example:
The page contains a div with id = "div_keycontent": <div id = "div_keycontent"> </div>
In Js, you can write as follows:
$. Each (data. list, function (I, item ){
$ ("# Div_keycontent "). append ("<li>" + item ["WikiTitle"] + "<a href = \" Read/"+ item [" WikiID "] +" \ "> View </ a> "+" </li> ");
});

Get (): Get Data asynchronously on the page. This method is in the form of asynchronous binding. I have explained it in my previous article. I will not talk about it here.

Spilt (): perform the following operations on strings:
Var str = spit ("liu, ming, feng ",",");
The returned str is a string array: {"liu", "ming", "feng "}

Substr (); for string operations, remove the sub-string
Usage:
/// Determine whether the last character is a comma
If (str. substring (str. length-1, str. length) = "," | str. substring (str. length-1, str. length) = ","){
Alert ("the last character is a comma !");
}

Html (): modify the content of an html Tag, for example:
$ ("# Div_keycontent" pai.html ("<p> no data </p> ");

Keyup (); trigger by pressing the keyboard
$ ("# TxtSearchKey"). keyup (function (){
$ ("# Div_keycontent" pai.html ("<p> data retrieval... </p> ");
});

Trim (): removes spaces at the beginning and end of a string.
Usage: str. trim ();

Show (): Display page elements, for example, $ ("# txtSearchKey"). show ();
Hide (): Hiding page elements such as: $ ("# txtSearchKey"). hide ();

Indexof (): Check whether the corresponding substring exists in the string.
Usage:
If (str. indexOf (',,')! =-1 | str. indexOf (',,')! =-1) {// determines whether a comma exists.
Alert ("two commas are used together !");
}

Related Article

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.