1. 程式人生 > >jquery排序與動態添加option以及屬性

jquery排序與動態添加option以及屬性

period sid item return append jquer base name cat

function getOrgansid() {
url="<%=basePath%>/rest/bsc/organ/selectOrganSidAllList";
$.ajax({
type:"POST",
url:url,
dataType:"json",
contentType: "application/json; charset=utf-8",
// data:,
success:function (data) {

if(data.res>0){
var $domOptions=data.data;
$domOptions.sort(function(a,b){return a.sid-b.sid});//排序

$.each($domOptions,function(n,value){
 $.each($domOptions,function(n,value){
// $("#se_organObject").append("<option sid="+value.sid+" value="+n+">"+value.organName+"</option>");//添加option
// $("#se_organObject").append($("<option></option>"));//添加option
$("#se_organObject").append($("<option>"));//添加option
$("#se_organObject option:eq("+n+")").attr("sid",value.sid);
$("#se_organObject option:eq("+n+")").attr("value",value.organName);
$("#se_organObject option:eq("+n+")").text(value.organName);
}
);

}
);
}else{
layer.msg("數據獲取失敗!",{offset:"100px"});
}
sid=[];
contentItem=[];
PeriodData=[];
PeriodData1={};
json={};
}
});

}


var organSid = $("#se_organObject option:selected").attr("sid");
alert(organSid);
if (typeof(organSid) === "undefined"){
organSid=10;
}

jquery排序與動態添加option以及屬性