jquery Action Form Related usage summary

Source: Internet
Author: User

The jquery implementation of the Select drop-down list onchange event:

Java code
  1. Jquery:
  2. $ (document). Ready (function () {
  3. $ ("#selectMenu"). Bind ("Change", function () {
  4. if ($ (this). val () = = "Pro1") {
  5. $ ("#pro1"). Slidedown ();
  6. $ ("#pro2"). Slideup ();
  7. }
  8. Else if ($ (this). val () = ="Pro2") {
  9. $ ("#pro2"). Slidedown ();
  10. $ ("#pro1"). Slideup ();
  11. }
  12. });
  13. });
  14. Html:
  15. <select id="Selectmenu" >
  16. <option value="" >please Select Product below</option>
  17. <option value="Pro1" >product 1</option>
  18. <option value="Pro2" >product 2</option>
  19. </select>

Java code
  1. 1.jQuery Basic operation for Select
  2. $ ("#select_id"). Change (function () { //code ...}); Add an event for Select, which is triggered when one of the items is selected
  3. var checkvalue=$ ("#select_id"). Val (); //Gets the value selected by Select
  4. var CheckValue = $ ('. FORMC select[@name = "Country"]). Val (); //Get the value of the selected item in the drop-down menu Name=country
  5. var checkvalue=$ ("#select_id"). Val (). Join (","); //Get the value of select multiple Select (multiple= "true")
  6. var Checktext = $ ("#select_id"). Find ("option:selected"). Text (); //Gets the text selected by Select
  7. var Checktext = $ ("select[@name =country] option[@selected]"). Text (); //Gets the text of the Select selected item (note that there are spaces in the middle)
  8. var Checktext = $ ("#select_id option:selected"). Text ();
  9. var CC2 = $ ('. FORMC select[@name = "Country"]). Val (); //Get the value of the selected item in the drop-down menu
  10. var cc3 = $ ('. FORMC select[@name = "Country"]). attr ("id"); //Get the ID property value of the selected item in the drop-down menu
  11. var checkindex=$ ("#select_id"). Get (0). SelectedIndex; //Gets the index value of select selection
  12. var maxindex=$ ("#select_id option:last"). attr ("index"); //Get the Select Maximum index value
  13. $ ("#select_id"). Get (0). SelectedIndex = 1; //Set the Select index value to 1 (the second item) to select
  14. $ (' #select_id ') [0].selectedindex = 1; //Set the Select index value to 1 (the second item) to select
  15. $ ("#select_id"). Val (4); //Set Select with a value of 4 for select
  16. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); //Set Select the text value for the jquery item selected
  17. $ ("#select_id"). attr ("value",'-sel3 '); //Set the VALUE=-SEL3 item as the currently selected item
  18. $ ("#select_id"). empty (); //Empty drop-down box
  19. $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); //Append an option to the Select (drop-down item)
  20. $ ("<option value= ' 1 ' >1111</option><option value= ' 2 ' >2222</option>"). AppendTo ("# select_id ")//Add drop-down box option
  21. $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); //Insert an option for select (first position)
  22. $ ("#select_id option:last"). Remove (); //Delete index value in select maximum option (last)
  23. $ ("#select_id option[index= ' 0 ']"). Remove (); //delete option with index value 0 in select (first)
  24. $ ("#select_id option[value= ' 3 ']"). Remove (); //delete option for value= ' 3 ' in select
  25. $ ("#select_id option[text= ' 4 ']"). Remove (); //delete option for text= ' 4 ' in select
  26. 2.jquery basic operation of the radio
  27. var item = $ (' input[@name =items][@checked] '). Val (); //Get a set of radio values for the selected item
  28. 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)
  29. $ (' input[@name =items] '). Get (1). checked = true; //radio The second element of a radio group is the currently selected value
  30. $ ("input[@type =radio]"). attr ("checked",' 2 '); //Set the value=2 item as the currently selected item
  31. $ ("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)
  32. 3.jquery Basic operation of the checkbox
  33. $ ("#checkbox_id"). attr ("value"); //Multi marquee checkbox
  34. $ ("input[@type =checkbox][@checked]"). Val (); //Gets the value of the check box for the first item selected
  35. $ ("input[@type =checkbox][@checked]"). each (function () { ////Because the check box is generally selected as multiple, you can loop the output
  36. Alert (this). Val ());
  37. });
  38. $ ("#chk1"). attr ("checked", "'); No tick .
  39. $ ("#chk2"). attr ("Checked",true); Tick
  40. if ($ ("#chk1"). attr (' checked ') ==undefined) //Determine if a tick has been made
  41. 4.jquery Basic operation of text
  42. $ ("#txt"). attr ("value"); //text box, text area:
  43. $ ("#txt"). attr ("value", "'); //Clear Contents
  44. $ ("#txt"). attr ("value",' one '); Populating content

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.