//var req = "type=" + $('#type').val();
$.post("/data/listDistributorFull.do", null, function(json) {
if(json.success !== true){
//提示报错
alert(json.message);
} else{
var oSelectParent = $('#distributorName'), html = '';
$.each([color=red]json.object[/color],function(i,n) {
console.log(n);
//var distributorName = n.distributorName=='undefined'?"--":n.distributorName;
html += '<option list="' + [color=red]json.object[/color].join("|") + '" value="' + n.distributorName + '">' + n.distributorName + '</option>';
});
oSelectParent.html('<option id="t" value="">请选择</option>' + html);
if(oSelectParent.html()){
$(".styled").select2(); //当Option的直存在时转换节点
listc();
function listc(){
var d=$(".select2-result");
var s=d.not( $(".select2-result").first());
[color=red]var list = $('#distributorName').children('option');[/color][align=left][/align] [color=red]//此处ID为页面dom [/color]
var arr=[];
$.each(list,function(index){
arr.push($(this).attr('list'));
});
arr.shift(0);
for(var i=0;i<s.length;i++){
s[i].setAttribute('list',arr[i]);
};
$.each(d,function(index){
$(this).click(function(){
if($(this).has('.select2-highlighted')&& $(this).text()!='请选择'){
var values = "";
var li=$(this).attr('list').split('|');
$.each(li,function(i,n) {
if(values != ""){
values += "\r\n";
}
values += n;
});
$('#key').val($(this).text());
$('#object').val(values);
}else{
$('#key').val('');
$('#object').val('');
}
});
});
};
}
}
});
function onModuleSelectChange(){
var oSelectParent = $('#distributorName'), oSelectChild = $('#service'),html = '', childHtml;[color=red]//distributorName 为页面domID[/color]
childHtml = '';
var list = oSelectParent.find(':selected').attr('list') !== undefined && oSelectParent.find(':selected').attr('list').split('|');
if(list){
var values = "";
$.each(list,function(i,n) {
if(values != ""){
values += "\r\n";
}
values += n;
}) ;
$('#key').val(oSelectParent.val());
$('#object').val(values);
};
};
var oSelectParent = $('#distributorName');
[color=red]//distributorName 为页面domID[/color]
oSelectParent.bind('change',function() {
onModuleSelectChange();
});
jquery 自动补全方案
最新推荐文章于 2024-08-30 20:29:15 发布