The jquery implementation of the Select drop-down list onchange event:
Java code
- Jquery:
- $ (document). Ready (function () {
- $ ("#selectMenu"). Bind ("Change", function () {
- if ($ (this). val () = = "Pro1") {
- $ ("#pro1"). Slidedown ();
- $ ("#pro2"). Slideup ();
- }
- Else if ($ (this). val () = ="Pro2") {
- $ ("#pro2"). Slidedown ();
- $ ("#pro1"). Slideup ();
- }
- });
- });
- Html:
- <select id="Selectmenu" >
- <option value="" >please Select Product below</option>
- <option value="Pro1" >product 1</option>
- <option value="Pro2" >product 2</option>
- </select>
Java code
- 1.jQuery Basic operation for Select
- $ ("#select_id"). Change (function () { //code ...}); Add an event for Select, which is triggered when one of the items is selected
- var checkvalue=$ ("#select_id"). Val (); //Gets the value selected by Select
- var CheckValue = $ ('. FORMC select[@name = "Country"]). Val (); //Get the value of the selected item in the drop-down menu Name=country
- var checkvalue=$ ("#select_id"). Val (). Join (","); //Get the value of select multiple Select (multiple= "true")
- var Checktext = $ ("#select_id"). Find ("option:selected"). Text (); //Gets the text selected by Select
- var Checktext = $ ("select[@name =country] option[@selected]"). Text (); //Gets the text of the Select selected item (note that there are spaces in the middle)
- var Checktext = $ ("#select_id option:selected"). Text ();
- var CC2 = $ ('. FORMC select[@name = "Country"]). Val (); //Get the value of the selected item in the drop-down menu
- var cc3 = $ ('. FORMC select[@name = "Country"]). attr ("id"); //Get the ID property value of the selected item in the drop-down menu
- var checkindex=$ ("#select_id"). Get (0). SelectedIndex; //Gets the index value of select selection
- var maxindex=$ ("#select_id option:last"). attr ("index"); //Get the Select Maximum index value
- $ ("#select_id"). Get (0). SelectedIndex = 1; //Set the Select index value to 1 (the second item) to select
- $ (' #select_id ') [0].selectedindex = 1; //Set the Select index value to 1 (the second item) to select
- $ ("#select_id"). Val (4); //Set Select with a value of 4 for select
- $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); //Set Select the text value for the jquery item selected
- $ ("#select_id"). attr ("value",'-sel3 '); //Set the VALUE=-SEL3 item as the currently selected item
- $ ("#select_id"). empty (); //Empty drop-down box
- $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); //Append an option to the Select (drop-down item)
- $ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("# select_id ")//Add drop-down box option
- $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); //Insert an option for select (first position)
- $ ("#select_id option:last"). Remove (); //Delete index value in select maximum option (last)
- $ ("#select_id option[index= ' 0 ']"). Remove (); //delete option with index value 0 in select (first)
- $ ("#select_id option[value= ' 3 ']"). Remove (); //delete option for value= ' 3 ' in select
- $ ("#select_id option[text= ' 4 ']"). Remove (); //delete option for text= ' 4 ' in select
- 2.jquery basic operation of the radio
- var item = $ (' input[@name =items][@checked] '). Val (); //Get a set of radio values for the selected item
- var rval = $ ("input[@type =radio][@checked]"). Val (); //Get the value of the selected item in the Radio box (note that there are no spaces in the middle)
- $ (' input[@name =items] '). Get (1). checked = true; //radio The second element of a radio group is the currently selected value
- $ ("input[@type =radio]"). attr ("checked",' 2 '); //Set the value=2 item as the currently selected item
- $ ("input[@type =radio][@value =2]"). attr ("checked",' checked '); //Set the Radio box value=2 to the selected state. (note there is no space in the middle)
- 3.jquery Basic operation of the checkbox
- $ ("#checkbox_id"). attr ("value"); //Multi marquee checkbox
- $ ("input[@type =checkbox][@checked]"). Val (); //Gets the value of the check box for the first item selected
- $ ("input[@type =checkbox][@checked]"). each (function () { ////Because the check box is generally selected as multiple, you can loop the output
- Alert (this). Val ());
- });
- $ ("#chk1"). attr ("checked", "'); No tick .
- $ ("#chk2"). attr ("Checked",true); Tick
- if ($ ("#chk1"). attr (' checked ') ==undefined) //Determine if a tick has been made
- 4.jquery Basic operation of text
- $ ("#txt"). attr ("value"); //text box, text area:
- $ ("#txt"). attr ("value", "'); //Clear Contents
- $ ("#txt"). attr ("value",' one '); Populating content