The core statement for getting the value of the drop-down list using js is: document. getElementById (id). options [Objsel. selectedIndex]. value;, but jquery is simpler.
Js to get the value of the drop-down list
The Code is as follows: |
Copy code |
<Fieldset> <Label> type </label> <Select name = "pid" id = 'pid '> <Option value = "0"> select </option> <Option value = "1"> PHP Learning Network </option> <Option value = "2"> PHP Learning Network </option> </Select> </Fieldset> <Fieldset> <Label> PHP Learning Network </label> <Select name = "sfk" id = 'sfk'> <Option value = "0"> select </option> <Option value = "0.3"> 30% </option> <Option value = "0.4"> 40% </option> <Option value = "0.5"> 50% </option> <Option value = "0.6"> 60% </option> </Select> </Fieldset> <Fieldset> <Label> PHP Learning Network http://www.bKjia. c0m </label> <Select name = "yfk" id = 'yfk '> <Option value = "0"> select </option> <Option value = "1"> 1 year </option> <Option value = "2"> 2 years </option> <Option value = "3"> 3 years </option> <Option value = "5"> 5 years </option> </Select> </Fieldset> <Fieldset> <Label> & nbsp; </label> <Input type = "button" onClick = "sikp ('pid ', 'sfk', 'yfk')"/> </Fieldset> </Div>
<Script type = "text/javascript"> Function sikp (p, s, y) { Var pid = getselval (p ); Var sfk = getselval (s ); Var yfk = getselval (y ); Window. open ("http://www.hzhuti.com" + pid + sfk + yfk); // link to a different place to add that value } // Obtain the value of the drop-down list Function getselval (id) { Var Objsel = document. getElementById (id) Var selval = Objsel. options [Objsel. selectedIndex]. value; Return selval; } </Script> |
Jquery obtains Select:
Obtain the selected text in the select statement:
The Code is as follows: |
Copy code |
$ ("# DdlRegType"). find ("option: selected"). text (); |
Obtain the value selected by the select statement:
The Code is as follows: |
Copy code |
$ ("# DdlRegType"). val (); |
Obtain the index selected by the select statement:
The Code is as follows: |
Copy code |
$ ("# DdlRegType"). get (0). selectedIndex; |
Set select:
Set the index selected by select:
The Code is as follows: |
Copy code |
$ ("# DdlRegType"). get (0). selectedIndex = index; // index |
Is the index value