如何单击按钮并删除选择选项

时间:2015-05-08 02:32:02

标签: javascript jquery

这是我的选择选项html代码

<select id="font">
        <option value="School">School</option>
        <option value="'Ubuntu Mono'">SansitaOne</option>
        <option value="Tangerine">Tangerine</option>
        <option value="Inconsolata">Inconsolata</option>
    </select>
    <button id="drop">Display</button>

这是我的javascript

<script type="text/javascript">
      $('#drop').click(function(event) {
            what to do here...
  });
    </script>

任何帮助都会很感激! 提前谢谢

1 个答案:

答案 0 :(得分:2)

也许请看下面的内容: http://www.w3schools.com/jsref/prop_select_selectedindex.asp

你应该能够做到:

$('#drop').click(function(event) { var x = document.getElementById("font").selectedIndex; var y = document.getElementById("font").options; alert("Index: " + y[x].index + " is " + y[x].text); });