0

This gets the value of whatever is selected in my dropdown menu.

document.getElementById('tester').value

I cannot however find out what property to go after for the text that's currently displayed by the drop down menu. I tried "text" then looked at W3Schools but that didn't have the answer, does anybody here know?

For those not sure, here's the HTML for a drop down box.

<select name="tester" id="tester">
    <option value="1">A skill</option>
    <option value="2">Another skill</option>
    <option value="3">Yet another skill</option>
</select>

Thanks

4

3 に答える 3

3

試す

var tester = document.getElementById('tester');
var text = tester.options[​​​tester.selectedIndex].innerHTML​;

デモ

于 2012-11-05T23:32:00.700 に答える
1

テキストは私には良さそうです - jsFiddle

$('#tester').on('change', function(){
    console.log($('option:selected', this).text()); 
});​
于 2012-11-05T23:31:09.630 に答える
1

私はあなたがこのようなものが欲しいと思います:

var d = document.getElementById('tester');
var selected_text = d.options[d.selectedIndex].text;

(これはテストされていませんが、あなたの答えはこれに似ているはずです)

于 2012-11-05T23:32:04.163 に答える