Jquery Usage Summary

Source: Internet
Author: User

JQuery API Chinese file address: http://www.hemin.cn/jq/index.html

JQuery Chinese Community: http://www.jquery.org.cn/

1.siblings ()

Gets a collection of elements that contain all unique sibling elements of each element in the matching element collection. You can filter by using an optional expression.

Sibling elements can only be set to a style of selected

$ele. Parent (). AddClass ("selected"). Siblings (). Removeclass ("selected");

2.ajax

$.ajax ({            URL: "/api/vshopprocess.ashx",            Type: ' Post ', DataType: ' json ', timeout:10000,            data: { Action: "Test", Testid:testid},            success:function (resultdata) {                if (resultdata! = null) {if ( Resultdata.status = = "1") {alert_h ("error"),} else {var STRs = "";}}); /csharp Code Public Voidtest (System.Web.HttpContext context) {string TestID = context. request["TestID"];}         

3. Toggle () If the element is visible, toggle to hidden, or toggle to visible if the element is hidden. Http://www.hemin.cn/jq/toggle.html

Closest (): starts with the element itself, matches the ancestor element progressively, and returns the first matching element. Http://www.hemin.cn/jq/closest.html

Nextall (): Finds all sibling elements after the current element. Http://www.hemin.cn/jq/nextAll.html

Click More once, show all, click once, Telescopic function Orderitemsdisplay (ele) {    //debugger;    var $tr = $ (ele). Closest ("tr"). Nextall ();    $tr. Each (function (index, TR) {        if (Index > 0) {            $ (TR). Toggle ();}}    )}   

4. var scrolltop = $ (window). scrolltop (); Gets the height of the scroll bar

5. Use of each

<input name= "CheckboxGroup" type= "checkbox" Value= ' <% #Eval ("OrderId")%> '/>var orderids = ""; $ ("Input : Checked[name= ' CheckboxGroup '). each (function () {orderids +    = $ (this). Val () + ",";}); function GetProductID () {    var v_str = "";    $ ("input[type= ' checkbox '][name= ' CheckboxGroup ']:checked"). each (function (RowIndex, Rowitem) {v_str + = $ (rowitem ). attr ("value") + ",";}); if (V_str.length = = 0) {alert ("Please select Commodity"); return "";} Return v_str.substring (0, V_str.length-1);}          

6. Writing methods can not be written in the DOM, do not write in the DOM. Can be done when the DOM is loaded

$ (document). Ready (function () {       $ (' #dropBatchOperation '). Bind ("Change", function () {selectoperation ();});} ), or
$ (function($) { $ ("#dropBatchOperation"). Bind ("Change", function () {selectoperation ();});});

7.Javascript Setting cookies

(1). Set Value: Setmycookie ("datacache_skushtml", skushtml);

(2). Value: var skushtml = Setmycookie ("datacache_skushtml");

Save CookiesfunctionSetmycookie (key, value) {if (arguments.length = = 1) {if(window.localstorage) {return Localstorage[key]; } else  {var objvalue = null ; var arrstr = Document.cookie.split (";" ); for (var i = 0; i < arrstr.length; i++ ) {var temp = arrstr[i].split ("=" ); if (temp[0] = =  key) {OBJV Alue = unescape (temp[1 ]); Break ;}} return  objvalue;}} else  {if  (window.localstorage) {if (typeof value! = "string" ) {value =  json.stringify (value);} Localstorage[key] =  value;} else  {var str = key + "=" +  Escape (value); var expires = 0 ; if (exp Ires > 0) {//0 without setting expiration time, the cookie automatically disappears when the browser shuts down var date = new  date (), var ms = expires * 3600 * + ; date.settim E (Date.gettime () +  ms); str + = "; expires= "+  date.togmtstring ();} document.cookie =  str;}}        

8.delegate delegate, delegate, event handlers that use the delegate () method apply to current or future elements (such as new elements created by scripts)

id = Grdproductskus is the parent dom of the current DOM, and if not, it can be written as document, $ (document). Delegate.

$ ("#grdProductSkus"). Delegate (". Ck_skuid", "Change", function () {        //At least one checkbox is not selected, remove all select        if (!$ (this) [ 0].checked) {            $ ("#chkAll"). Removeattr ("checked");        }        If all of the following are selected, then select        var chk = 0;        var $eleSkuId = $ (". Ck_skuid");        $eleSkuId. Each (function (i, Elem) {if ($ (elem) [0].checked) {chk++;}}), if ($eleSkuId. length > 0 & ;& $eleSkuId. length = chk) {$ (": CheckBox"). attr ("Checked", "checked");}); Select All and uncheck $ (". Backaddorder_tb"). Delegate (' #chkAll ', "change", function () {var flag = $ (this) [0].checked; var $e Leskuid = $ (". Ck_skuid"); $eleSkuId. each (function (i, N) {$ (n) [0].checked = flag;});});  

9. (1) Json.parse () converts a JSON string into an object

var jsontext = ' {' FirstName ': "Jesper", "surname": "Aaberg", "Phone": ["555-0100", "555-0120"]} '; var contact =  Json.parse (Jsontext); document.write (Contact.surname + "," + contact.firstname);  Output:aaberg, Jesper  

(2) json.stringify () converts an array into a JSON string

The following shows how to use Json.stringify to convert an array to a JSON string and then use Json.parse to convert the string to a group. var arr = ["A", "B", "C"]; var str = json.stringify (arr); document.write (str); document.write ("<br/>");  var newArr = json.parse (str);  while (Newarr.length > 0) {document.write (Newarr.pop () + "<br/>");}//Output://["A", "B", "C"]//C b//A     

How to pass the value between 10.IFRAME windows, such as a page Open b page, you need to pass the value of page B to the a page, where a is an IFRAME nested reference page.

A page, defining a global variable

Window.skuslistvalue = [];

b page, skusstr the value of the B page

Window.top.frammain.skusListvalue = Skusstr;,frammain is the ID of the IFRAME

Then a page skuslistvalue can be taken to the value.

Close the window, you can call window.parent.$ (". Aui_close"). Click ();

Window.parent Description Window.parent can get the parent window or parent frame of a frame. The parent of the top-level window refers to itself.
You can use this feature to determine whether the window is a top-level window

Jquery Usage Summary

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.