开发者

How to identify when select option was selected (not necessarily changed)?

开发者 https://www.devze.com 2023-01-11 23:28 出处:网络
The following code displays the new selected value if it is different from the current value: HTML: <select>

The following code displays the new selected value if it is different from the current value:

HTML:

<select>
    <option value='123'>123</option>
    <option value='456'>456</option>
    <option value='789'>789</option>
</select>

JS:

$(function() {
    $('select').change(function() { alert($(this).val()); });
});

I would like to display the value w开发者_StackOverflow中文版henever an option selected (even if it is the currently selected value).

How could I achieve this ?


Hook on the click event. It'll be a bit more often fired, but that's the best you can get.

0

精彩评论

暂无评论...
验证码 换一张
取 消