使用jQuery设置选择标签的选择选项 [英] setting the selected option of a select tag with jquery
本文介绍了使用jQuery设置选择标签的选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的jquery函数如下:
If my jquery function is as below:
$('#shifts').change (function ()
{
$.get('ajax/time_menus.php', { shift: $('#shifts').val() },
function(data)
{
$("#test").html( data );
});
并返回一个包含两个时间值的数组,该时间值包含在六个值的数组中: [hours] [minutes] [ampm] [hours] [minutes] [ampm]
And returns a array with two time values contained in an array of six values: [hours][minutes][ampm][hours][minutes][ampm]
如何设置6个相关菜单的值以显示我刚刚加载的两次.
How would I set the values of 6 correlated menus as to display the two times I just loaded.
是否可以通过jquery设置值,还是最好在php中构建整个菜单,然后将其传递回并设置html.
Is there a way to set the value via jquery or is it better to build the entire menu's in php and then pass them back and set the html.
推荐答案
使用jQuery,您可以使用val
函数select
不同的<option>
:
With jQuery, you can select
different <option>
s with the val
function:
$('#my-select').val(yourValue);
这篇关于使用jQuery设置选择标签的选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文