JQuery binds the onchange event of the Select Tag, pops the selected value, and implements the jump, argument

Source: Internet
Author: User
[HTML] View plain copy <script src= "jquery.min.js"  type= "Text/javascript" ></script>   <script language= "JavaScript"  type= "Text/javascript" >   $ (document). Ready (function () {    $ (' #mySelect '). Change (function () {   alert ($ (this). Children (' option:selected '). Val ());    var p1=$ (this). Children (' option:selected '). Val ();//This is the selected value    var p2=$ (' # Param2 '). Val ()//Get the value of other labels on this page    window.location.href= "xx.php?param1=" +p1+ "¶m2=" "+p2+" ";//page jump and pass parameter    })   })    </script>      <select id= "Myselect" >    <option value= "1" >one</option>   <option value= "2"  selected = "Selected" >two</option>   <option value= "3" >three</option>   < /select>   <input type= "text"  value= "ooo"  name= "param2"  id= "param2"/>& nbsp; 
jquery Gets the text and value selected by select
Gets the text: $ ("#ddlregtype") selected by select. Find ("option:selected"). Text ();
Gets the value: $ ("#ddlregtype") selected by select. Val ();

Gets the index selected by select: $ ("#ddlregtype"). Get (0). SelectedIndex;


1. Get the value and text,html code for select Select as follows:[HTML]View plain copy <select id= "Myselect" > <option value= "1" >one</option> <option value= "2" >two&lt ;/option> <option value= "3" >three</option> </select>
You can get the selected value and text from the following script code s[JavaScript]View Plain Copy $ ("#mySelect"). Val (); Gets the value value of the selected record $ ("#mySelect option:selected"). Text (); Gets the text value of the selected record
2, the use of new option ("Text", "value") method to add Options option[JavaScript]View plain copy var obj = document.getElementById ("Myselect");    Obj.add (New Option ("4", "4")); 3, delete all options option[JavaScript]View plain copy var obj = document.getElementById ("Myselect"); obj.options.length = 0;
4, Delete selected options option[JavaScript]View plain copy var obj = document.getElementById ("Myselect");   var index = Obj.selectedindex; Obj.options.remove (index);
5, modify the selected options option[JavaScript]View plain copy var obj = document.getElementById ("Myselect");   var index = Obj.selectedindex; Obj.options[index] = new Option ("three", 3); Change the corresponding value obj.options[index].selected = true; Remain selected
6. Delete Select[JavaScript]View plain copy var obj = document.getElementById ("Myselect"); Obj.parentNode.removeChild (obj); Remove Current Object
7. Select Selected Response Event[JavaScript]View Plain Copy $ ("#mySelect"). Change (function () {//Add action code to be performed})

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.