jQuery - 在选择框中选择选项 [英] jQuery - select option in select box

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

问题描述


可能重复:

jQuery /以编程方式选择选择框中的选项

我想知道,是否可以直接从jQuery中选择selectbox / combobox中的选项。例如,我想在select中选择值为5的选项,值为1到10.

I was wondering, is it possible to select an option from a selectbox/combobox directly from jQuery. For example I want to select the option with the value 5 in a select with values from 1 to 10.

我能想到的唯一解决方案是删除所有选项和使用正确的选择值重新创建它们,但这有点效率不高。

The only solution I can think of is to remove all options and recreate them with the right selected value, but that's a bit unefficient.

推荐答案

只需像对待任何其他输入一样对待选择框element:

Just treat the select box as you would any other input element:

$("#MySelectBox").val("5");

这篇关于jQuery - 在选择框中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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