当前位置:Gxlcms > JavaScript > jQuery选中select控件 无法设置selected的解决方法

jQuery选中select控件 无法设置selected的解决方法

时间:2021-07-01 10:21:17 帮助过:5人阅读

解决办法:把选中option的语句放到setTimeout中,例:
代码如下:

setTimeout(function() {
var selSorts = $("select[id^='" + controls.selsort + "']");
$.each(selSorts, function(index, sort) {
var ope = $(sort).find("option[value='" + arrSort[index] + "']");
if (ope.length > 0)
ope[0].selected = true;
});
}, 1);

人气教程排行