A summary of common operational functions of jquery objects (1/2)

Source: Internet
Author: User
Tags bind set time

$ ("label name")//Fetch HTML element document.getElementsByTagName ("")

$ ("#id")//Fetch single control document.getElementById ("")

$ ("div #id")//Fetch controls in a control

$ ("#id #id")//control by control ID


$ ("label. Class style name")//Use class to fetch control

$ ("#id"). Val (); Take value

$ ("#id"). Val (""); assigning values

$ ("#id"). Hide (); Hide

$ ("#id"). Show (); Show

$ ("#id"). Text (); Equivalent to taking innerHTML

$ ("#id"). Text (""); Equivalent to Innerhtml= ""

$ ("#id"). CSS Tutorial ("Properties", "value")//Add CSS Styles

$ ("form# form ID"). Find ("#所找控件id"). End ()//traverse the form

$ ("#id"). Load ("*.html")//Load a file

For example:

$ ("Form#frmmain"). Find ("#ne"). CSS ("Border", "1px solid #0f0"). End ()/() return form

. Find ("#chenes"). CSS ("Border-top", "3px dotted #00f"). End ()

$.ajax ({url: "result.asp tutorial X",//URL of the data request page

Type: ' Get ',//data transfer mode (GET or POST)

DataType: "HTML",//expecting data to be returned in data format (e.g. "XML", "HTML", "script", or "JSON")

Data: "Chen=h",///pass parameter string for the datum, only for Get way

timeout:3000,//Set time delay request

Success:function (MSG)//Trigger function when request is successful
{
$ ("#stats"). Text (msg);
},
Error:function (MSG)//functions that are triggered when a request fails
{
$ ("#stats"). Text (msg);
}
});

$ (document). Ready (function () {});
$ ("#description"). Mouseo Tutorial ver (function () {});

Ajax methods

$.get ("result.aspx",//URL of the data request page
{chen: "Test", Age: "25"},///pass parameter string of data
function (data) {alert ("Data loaded:" + data);} The function after the trigger
);
});
});

Get the selected value of the dropdown menu

$ (#testselect option:selected '). Text (); Fetching text values
or $ ("#testselect"). Find (' option:selected '). Text ();
or $ ("#testselect"). Val ();

------

Summary of common function methods in jquery

Event handling

Ready (FN)

Code:
$ (document). Ready (function () {
Your code here ...
});

Role: It can greatly improve the response speed of Web applications. By using this method, you can immediately call the function you are binding when DOM loading is ready to be read and manipulated, and 99.99% of Web page effects functions need to be executed at that moment.

Bind (TYPE,[DATA],FN)

Code:
$ ("P"). Bind ("click", Function () {
Alert ($ (this). text ());
});

Function: Bind an event handler function to a specific event (like click) for each matching element. Play the role of event monitoring.

Toggle (FN,FN)
Code:

$ ("TD"). Toggle (
function () {
$ (this). AddClass ("selected");
},
function () {
$ (this). Removeclass ("selected");
}
);

function: Switch the functions you want to call each time you click. If a matching element is clicked, the first specified function is triggered, and when the same element is clicked again, the specified second function is triggered. A very interesting function that may be used when implementing certain functions dynamically.

(Like click (), focus (), KeyDown () such events are not mentioned here, those are more commonly used in development. )

home 1 2 last

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.