2 に答える
0
あなたの必要性を完全に理解しているかどうかはわかりませんが、答えようとします.
あなたがjQueryについて話しているように、私はこの解決策を持っています:
$("#my-select").change(function() {
// $(this) refers to the select element
$(this).find("option:selected").each(function() {
// this function is called only once per change
// $(this) refers to the selected option
})
});
実際の例:
$("#my-select").change(function() {
// $(this) refers to the select element
$("#s_value").text($(this).val());
$("#s_text").text($(this).find("option:selected").text());
$(this).find("option:selected").each(function() {
// this function is called only once per change
// $(this) refers to the selected option
$("#o_value").text($(this).val());
$("#o_text").text($(this).text());
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="my-select">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<br>SELECTED (FROM SELECT) :
<br>Value : <span id="s_value"></span>
<br>Text : <span id="s_text"></span>
<br>
<br>SELECTED (FROM OPTION) :
<br>Value : <span id="o_value"></span>
<br>Text : <span id="o_text"></span>
<br>
<br>
于 2015-10-15T12:49:24.187 に答える