JS Practical Application

Source: Internet
Author: User

1-----------------------------Gets the value selected by select-------------------------2 native JS Gets the selected select Value3 varobj = document.getElementById ("Testselect");//Location ID4 varindex = Obj.selectedindex;//Check Index5 varText = Obj.options[index].text;//Select text6 varvalue = Obj.options[index].value;//checked Values7 get selected Select value in jquery8 The first way9$ (' #testSelect option:selected '). Text ();//the selected textTen$ (' #testSelect option:selected '). Val ();//the selected value One$ ("#testSelect"). Get (0). SelectedIndex;//Index A The second way -$ ("#tesetSelect"). Find ("option:selected"). Text ();//the selected text -$ ("#tesetSelect"). Find ("option:selected")). Val (); the$ ("#tesetSelect"). Find ("option:selected"). Get (0). SelectedIndex; --------------------------gets the value of radio selected---------------------------- - get selected Select value in jquery - varInthot = $ ("input[name= ' Radhot ']:checked"). Val (); + native JS Gets the selected select Value - functionSetradio (v) { +robj=Document.form1.radioname; A  for(i=0;i<robj.length;i++){ at if(robj[i].value==v) { -Robj[i].checked=true; -     } -     } - } -Window.onload =function(){     in         varfrult= document.getelementsbyname (' Frult ')); -          for(i=0;i<frult.length;i++){ to             if(frult[i].checked) { + alert (frult[i].value); -             } the         } *     } $-------------------------Gets the text selected radio----------------------------Panax Notoginseng$ ("Input[name= ' Sex ']:checked") [0].nextsibling.nodevalue; -    the-------------------------gets the value of the check check---------------------------- + get selected Select value in jquery A Method 1 the$ ("#dxbox Li"). each (function(){ +     if($( This). Find ("input[type=checkbox]:checked"). val ()! =undefined) -     { $Alert ($ ( This). Find ("input[type=checkbox]:checked"). Val ()); $     } - }); - Method 2 the$ ("Input:checkbox[name= ' Checkmanager ']:checked"). each (function(){ -         if( This. Checked) {WuyiAlert ($ ( This). Next (). text ()); the         } -     }); Wu------------------------------gets the length of the check check---------------------- - varCount = $ ("input:checkbox[name= ' Checkone ']:checked"). length; About     if(count<1){ $Alert (' Please select a customer to assign '); -         return false; -     } -------------------------------scroll bar------------------------------------ AAlert ($ (window). Height ());//Browser Current window viewable area height +Alert (document). Height ());//the height of the browser's current window document theAlert ($ (document.body). Height ());//the height of the body of the browser's current window document -Alert ($ (document.body). Outerheight (true));//Browser Current Window document body total height includes border padding margin $Alert ($ (window). width ());//Browser Current window viewable area width theAlert (document). width ());//Browser Current Window Document object width theAlert ($ (document.body). width ());//the height of the body of the browser's current window document theAlert ($ (document.body). Outerwidth (true));//Browser Current Window document body total width includes border padding margin the------------------------------------------------------------------------ - //$ (window). ScrollTop () This method is the distance that the current scroll bar scrolls in //A $ (window). Height () Gets the height of the current form the //$ (document). Height () Gets the altitude of the current document the varbot = 50; About //bot is the height of the bottom distance the //When the bottom base distance + scrolling height 〉= The height of the document-the height of the form; the //we need to load the data asynchronously. the------------------------------------------------------------------------ + Cookies - functionSetcookie (Name,value)//two parameters, one is the name of the cookie, and the other is the value the {Bayi      vardays = 180;//This cookie will be saved for 30 days the      varExp =NewDate ();//New Date ("December, 9998"); theExp.settime (Exp.gettime () + days*24*60*60*1000); -Document.cookie = name + "=" + Escape (value) + "; expires=" +exp.togmtstring (); - } the functionGetCookie (name)//take a cookie function the { the      vararr = Document.cookie.match (NewRegExp ("(^|)" +name+ "= ([^;] *)(;|$)")); the       if(Arr! =NULL)returnUnescape (arr[2]);return NULL; - } the functionDelcookie (name)//Delete Cookies the { the      varExp =NewDate ();94Exp.settime (Exp.gettime ()-1); the      varCval=GetCookie (name); the      if(cval!=NULL) document.cookie= name + "=" +cval+ "; expires=" +exp.togmtstring (); the }98------------------------------------------------------------------------- About-----------------------JS matches a string to replace a------------------------ - varstr = "I want to eat, I want to eat, I want to eat, I want to eat, I want to eat";101Alert (str.replace (' eat ', ' bathe '));102-----------------------JS replaces all strings that match------------------------103 varstr = "I want to eat, I want to eat, I want to eat, I want to eat, I want to eat";104Alert (Str.replace (NewREGEXP (/meal/g), ' bathing ')); the 106 107 //Select All Code108$ (". Qudao_type"). Click (function(){109           vari = $ (". Qudao_type")). length; the           varJ = $ (". Qudao_type:checked"). Length111           if(i==j) { the$ ("#qd_manager_type"). attr (' checked ',true);113           } the           if(j==0){ the$ ("#qd_manager_type"). Removeattr ("checked"));  the           }117});

JS Practical Application

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.