0
我有一个显示选项的选择框。当用户选择一个选项时,我使用XMLHttpRequest根据第一个选择的值获取另一个选择框。 当用户正在选择选项时,此工作正常。 当用户现在想编辑它时,我使用Jquery从选择框中预选每个项目,并自动生成他以前选择的选项。 最多有5个选择框。 我使用setTimeout来运行下一个“选择值”函数。使用jquery和XMLHttpRequest从多个选择框中预选选项
该脚本在Chrome浏览器中正常工作,但在其他浏览器中无法正常工作。
这里是我的代码:
function oc(a)
{
var o = {};
for(var i=0;i<a.length;i++)
{
o[a[i]]='';
}
return o;
}
var allcats = new Array(<? echo substr($catarr, 0, -1); ?>);
$("#catchoice1 option").each(function() {
var name = $(this).val();
if(name in oc(allcats)) {
var selectedcategory = name;
setTimeout(catpop1(selectedcategory),1000,true); /// getting a script error on this line in IE.
setTimeout(catpop2,1000,true);
$("#catschosen").attr('disabled', false);
$("#catschosen").attr('checked', true);
$("#Tags3").attr('disabled',false);
}
});
function catpop1(name) { $("#catchoice1 option[value="+name+"]").attr('selected', 'selected').change(); };
function catpop2() {
$("#catchoice2 option").each(function() {
var name = $(this).val();
if(name in oc(allcats)) {
var selectedcategory = name;
$("#catchoice2 option[value="+name+"]").attr('selected', 'selected').change();
}
});
setTimeout(catpop3,1000,true);
$("#catschosen").attr('checked', true);
$("#Tags3").attr('disabled',false);
};