如何使用jQuery从HTML选择框中选择选项?

如何使用jQuery从HTML选择框中选择选项?,jquery,html,jquery-selectors,html-select,Jquery,Html,Jquery Selectors,Html Select,如何使用jQuery从HTML选择框中选择选项?我使用的是选择框(单选),而不是下拉框。我需要得到选择值和文本 这是我的代码,但缺少jQuery函数: <html> <head> <script type='text/javascript'> val choiceVal = "None!"; val choiceText = "None!"; //So what is the function? <

如何使用jQuery从HTML选择框中选择选项?我使用的是选择框(单选),而不是下拉框。我需要得到选择值和文本

这是我的代码,但缺少jQuery函数:

<html>
  <head>
    <script type='text/javascript'>
      val choiceVal = "None!";
      val choiceText = "None!";
      //So what is the function?
    </script>
  </head>
  <body>
    <select id="myListChoices">
      <option value="1">Choice 1</option>
      <option value="2">Choice 2</option>
      <option value="3">Choice 3</option>
    </select>
  </body>
</html>

val choiceVal=“无!”;
val choiceText=“无!”;
//那么功能是什么呢?
选择1
选择2
选择3

更多说明:请注意,我的问题的目标是编写一个处理程序,在单击列表项时返回所选的值和/或文本。因此,例如,如果用户单击页面中的“选项2”,jQuery应该以某种方式(如何?)触发警报或使用所选值/文本填充变量。

您捕获了选择列表的
更改
事件

$('select').on('change', function () {
    alert($('option:selected').val() +' : '+ $('option:selected').text());
});
在上面,我们根据需要返回所选选项val()和text()