The problem with the Select drop-down box is that after selecting an option, I want the front-end display to change and know which option was selected.
This is easy to solve:
is 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>男装</option> <option>女装</option> <option>童装</option> <option已通过审核商家</option> </select> </div> </div>
JS:
function selectOnchang(obj){ //获取被选中的option标签选项 alert(obj.selectedIndex); }
What is used here is onchange and selectedIndex. The
onchange event occurs when the content of the field changes. The
onchange event can also be used to trigger events after radio button and check box changes.
selectedIndex: Set or return the index number of the selected item in the drop-down list.
In this way, the change event will be triggered when we change the option.
In this way, we can only get which item is selected, and if we select which item, we need to send 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">男装</option> <option value="wemen">女装</option> <option value="childe">童装</option> <option value="yunfu">孕妇装</option> </select> </div> </div>
That is to say, when I select it, I want to get the value. What should I do at this time.
There is only one method to achieve this, there should be many other methods.
function selectOnchang(obj){ var value = obj.options[obj.selectedIndex].value; alert(value); }