使用jquery设置select标签的选定选项
如果我的jquery函数如下:
$('#shifts').change (function () { $.get('ajax/time_menus.php', { shift: $('#shifts').val() }, function(data) { $("#test").html( data ); });
并返回一个数组,其中包含六个值的数组中包含的两个时间值:[小时] [分钟] [安培] [小时] [分钟] [安培]
如何设置6个相关菜单的值,以显示我刚加载的两次。
有没有办法通过jquery设置值或者更好的是在php中构建整个菜单然后将它们传回并设置html。
使用jQuery,您可以使用val
函数select
不同的 :
$('#my-select').val(yourValue);
$('#my-select option[value="yourValue"]').attr('selected','selected');