Jquery beginner's notes (1)

Source: Internet
Author: User

1,
Ajax: Asynchronous JavaScript and XML (first review Ajax)

VaRXMLHttpRequest;

FunctionAjaxtest ()

{

If(Window. activexobject)

XMLHttpRequest =NewActivexobject ("Microsoft. XMLHTTP ");

// XMLHttpRequest = newactivexobject ("msxml2.xmlhttp"); // suitable for new ie versions, but the above can also be used

Elseif(Window. XMLHttpRequest)

XMLHttpRequest =NewXMLHttpRequest ();

 

If(XMLHttpRequest! = "Undefined ")

// If ("undefined "! = XMLHttpRequest) // do not recommend this method. It may be incorrect in IE.

{

// Prepare data, GET request; url = ajaxservlet; true indicates asynchronous Processing

VaRUrl = "$ {pagecontext. Request. contextpath}/ajaxservlet ";

// Submit the request in get mode, with parameters following the URL

/* XMLHttpRequest. Open ("get", URL, true );

XMLHttpRequest. onreadystatechange = ajaxcallback; // callback function

XMLHttpRequest. Send (null); // send the request

*/

// Submit in post Mode

XMLHttpRequest. Open ("Post", URL,True);

XMLHttpRequest. onreadystatechange = ajaxcallback ;//
Callback Function

VaRJSON = {"001": "A", "002": "B "};

XMLHttpRequest. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); // you must add

XMLHttpRequest. Send ("JSON =" + JSON. stringify (JSON ));
// Send the request

}

 

}

 

FunctionAjaxcallback ()

{

If(XMLHttpRequest. readystate = 4)

{

If(XMLHttpRequest. Status = 200)

{


VaRJSON = eval ('+ XMLHttpRequest. responsetext + ')');


For(VaRIIn
JSON)


{

Alert (I +
"," + JSON [I]);


}

}

}

}

2. www.jquery.com: write less, do more

<Scripttype ="Text/JavaScript"Src =Jquery-1.7.2.js"> </SCRIPT>

<Scripttype ="Text/JavaScript">

// After the DOM file is loaded, it will be executed in sequence. The onload event is an object reference. After the page is loaded and the related preparations such as the association number Dom are completed, the task will be executed, and only the last reference will be executed.

$ (Document). Ready (Function()

{

Alert ("hello ");

});

 

$ (Document). Ready (Function()

{

Alert ("world ");

});

</SCRIPT>

The HTML elements obtained by jquery are in the form of arrays.

VaR d = Document. getelementbyid ("div1 ");

Alert (D. innerhtml );

// The function of converting Dom to jquery object is extended

VaR JD = $ (d );

Alert(jd.html ());

// Jquery object --> convert to DOM object

VaR E = $ ("A") [0];

Alert (E. innerhtml );

3. jquery Selector

////////// First check the CSS selector.

A. Tag selector, which uses the Tag Name of the document element as the selector

B. ID selector, id value of an element attribute in the document

C. The class selector Div. x applies to the class = "X" element in the DIV element, and. X indicates to reference all document elements whose class = "X" is referenced in the document.

D. Group selector TD, TB, Div. {...}

E. Descendant selector # links

F. wildcard selector * indicates all content

/////////// Jquery Selector

 

 

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.