Select the dropdown box to select and value the solution _jquery

Source: Internet
Author: User

Select the dropdown box, and when you select an option, the foreground displays a change, and you know which options are selected.

This is a good solution:

As follows:

<div class= "Page-header" >
<div class= "Form-horizontal" >
<div class= "Control-label col-lg-0" >
</div>
<div class= "col-lg-2" >
<select class= "Form-control" onchange= " Selectonchang (This) ">
<option> men </option>
<option> Women's </option>
< Option> Children's Wear </option>
<option have passed the audited merchant </option>
</select>
</div>
</div>

Js:

function Selectonchang (obj) { 
//Get the selected option label option 
alert (obj.selectedindex);
}

The onchange and SelectedIndex are used here.

The onchange event occurs when the contents of the domain change.

The onchange event can also be used for events that are triggered when a radio box and a check box change.

SelectedIndex: Sets or returns the index number of the selected item in the Drop-down list.

This will trigger a change when we change the option.
In doing so, we can only get the selected item, and if we select which item, we need to pass special information, what should we do at this time?

<div class= "Page-header" >
<div class= "Form-horizontal" >
<div class= "Control-label col-lg-0" >
</div>
<div class= "col-lg-2" >
<select class= "Form-control" onchange= " Selectonchang (This) ">
<option value=" Men "> Menswear </option>
<option value=" wemen "> Ladies </ option>
<option value= "Childe" > Children's Wear </option>
<option value= "Yunfu" > Maternity dress </option>
</select>
</div>
</div>

In other words, I want to get that value when I select it, and how to do it at this time.

There is only one way to do this, and there should be plenty of other ways.

function Selectonchang (obj) { 
var value = Obj.options[obj.selectedindex].value;
alert (value);
}

The above is a small set for you to introduce the Select dropdown box and value of the solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.