jquery obtains the value of select option and the action "transfer" to select option

Source: Internet
Author: User

gets select: Gets the Select selected text: $ ("#ddlRegType"). Find ("option:selected")). text (); Gets the value selected by select: $ ("#ddlRegType"). Val (); Gets the selected index of select: $ ("#ddlRegType"). Get (0). SelectedIndex; Set Select: Sets the index selected by select: $ ("#ddlRegType"). Get (0). Selectedindex=index;//index is the indexed valueSet Select to select the value: $ ("#ddlRegType"). attr ("Value", "Normal "); $("#ddlRegType"). Val ("Normal")); $("#ddlRegType"). Get (0). value = value; Set the Select Selected Text:var count=$ ("#ddlRegType option"). length; for (Var i=0;i<count;i++) {if ($ ("#ddlRegType"). Get (0). Options[i].text = = text) {$ ("#ddlRegType"). Get (0). options[i].selected = true;          Break }      } $("#select_id option[text= ' jQuery ']"). attr ("Selected", True); Set the Select option entry: $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Add an option$("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>");//Insert an option in front$("#select_id option:last"). Remove ();//Remove the most indexed value option$("#select_id option[index= ' 0 ']"). Remove ();//Delete option with index value 0$("#select_id option[value= ' 3 ']"). Remove ();//Delete option with a value of 3$("#select_id option[text= ' 4 ']"). Remove ();//Delete option with a text value of 4Empty select:$ ("#ddlRegType"). empty (); jquery Gets the value:. val (). Text () Setting value. val (' Set the value here ')  $("Document"). Ready (function(){ $("#btn1"). Click (function(){ $("[Name= ' checkbox ']"). attr ("Checked", ' true ');//Select All}) $("#btn2"). Click (function(){ $("[Name= ' checkbox ']"). Removeattr ("checked");//Cancel Select all}) $("#btn3"). Click (function(){ $([name= ' checkbox ']:even '). attr ("Checked", ' true ');//Check all odd}) $("#btn4"). Click (function(){ $("[Name= ' checkbox ']"). each (function(){//Inverse Selectionif($( This). attr ("Checked")){ $( This). Removeattr ("Checked"); } Else{ $( This). attr ("Checked", ' true '); } }) }) $("#btn5"). Click (function(){//Output the selected valuevarStr= ""; $("[name= ' checkbox '][checked]"). each (function() {str+=$( This). Val () + "\ r \ n"; //alert (This). Val ());}) alert (str); }) })

Original address: http://www.cnblogs.com/summer_adai/archive/2012/12/01/2797145.html

jquery obtains the value of select option and the action "transfer" to select option

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.