我有6个具有相同选项的选择框。但我想根据标签预选它们。
$.each(employees, function(key,val) {
emp+= '<option value='+val.field+'>'+key+'</option>';
});
if (data.length < 13) {
label_dropdown += '<form name="import_emp_chose" id="import_emp_chose" class="col-md-offset-3">';
label_dropdown += '<div class="form-group col-md-9"><label style="color: #00bfff;" class="control-label txtColor text-right import-label-text col-md-3">ATTENDANCE EXCEL FIELDS</label><label style="color: #00bfff;padding-left:14px;" class="control-label txtColor text-left import-label-text col-md-4">ATTENDANCE MAPPING FIELDS</label></div></div>';
for(var i=0;i<data.length;i++){
if ( data[i]!=0 && data[i]!==null) {
excel_title = capitalizeFirstLetter(data[i]);
label_dropdown += '<div class="form-group col-md-9">';
label_dropdown += '<label name="'+data[i]+'" id="'+data[i]+'" class="control-label labeltxt text-right import-label-text col-md-3">'+excel_title+'</label>';
label_dropdown += '<div class="col-md-4">';
label_dropdown += '<select class="form-control col-md-3 dropdown_field" name="'+data[i]+'">'+emp+'</select>';
label_dropdown += '</div><span style="color: #ff5050;" class="help-block hidden '+data[i]+'_error">This field already mapped.</span>';
label_dropdown += '</div>';
}
dosettimeout(i);
}
}
function dosettimeout(i){
setTimeout(function(){
$('.dropdown_field option[value ="'+i+'"]').attr('selected',true);
}, 2000);
}
我有以下代码。 dosettimeout()
功能正在选择该选项,但它为所有选择下拉列表选择了相同的选项。如何根据标签选择选项?
答案 0 :(得分:0)
您没有关闭选项选择器中的括号。它应该是:
document.body.appendChild(buildHtmlTable([
{"name" : "abc", "age" : 50},
{"age" : "25", "hobby" : "<span class=\'axis-download\'>fff</span>"},
{"name" : "xyz", "hobby" : "programming"}
]));
这样可以解决吗?