jquery选择选项点击处理程序 [英] jquery select option click handler

查看:98
本文介绍了jquery选择选项点击处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出:

given:

<select id="mySelect">
  <option>..</option>
  ...
</select>

使用select id,我如何在其中一个选项上触发点击事件?我尝试将事件直接附加到select,但是这会在点击选择时触发事件(即使没有选项)。哦,这是一个多选(虽然我不认为这件事)。

Using the select id, how can I trigger a click event on one of the options? I tried attaching the event directly to the select, but this triggers an event whenever the select is clicked on (even if there are no options). Oh, and it is a multi-select (although I don't think that matter).

推荐答案

您想要更改',而不是'click'。

You want the 'change' event handler, instead of 'click'.

$('#mySelect').change(function(){ 
    var value = $(this).val();
});

这篇关于jquery选择选项点击处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆