0

選択メニューには次のコードがあります。

<label for="select-choice-0" class="select">Shipping method:</label>
<select name="select-choice-0" id="select-choice-1">
   <option value="standard">Standard: 7 day</option>
   <option value="rush" >Rush: 3 days</option>
   <option value="express">Express: next day</option>
   <option value="overnight">Overnight</option>
</select>

$('select-choice-1').val() を実行すると、選択したオプションの値が得られます。たとえば、2 番目のオプションが選択されている場合、返される値は「rush」になります。

ただし、代わりに「Rush: 3 days」という文字列を取得したいと考えています。どうやってやるの?

ありがとう。

4

1 に答える 1

0

以下の作品を発見。

document.getElementById('select-choice-1').options[document.getElementById('select-choice-1').options.selectedIndex].text;
于 2012-05-04T01:20:13.790 に答える