[color=indigo][color=indigo]
方法一:
$('#selectId').change(function (){
$.ajax({
url:url,
type:'post', //資料發送方式
dataType:'xml', //接受資料格式
data:'par_int_org_id='+$("select[@id='select1'] option[@selected]").val(), //要傳遞的資料
error:function(json){
alert( "not lived!");
},
success: function(xml){
$("#selectId2").html('');//清空2号下拉框
$(xml).find("select").each(function(){
var id=$(this).attr("id"); //擷取傳回的ID
var name=$(this).text(); //擷取傳回的NAME
$('<option value='+id+'>'+name+'</option>').appendTo('#select2'); //添加下拉框
$("#selectId2").attr('disabled','') //2号下拉框可用
}
);
$('<option value="">---請選擇---</option>').appendTo('#selectId2');
}
});
});
方法二:
$('#selectId').change(function (){
$.ajax({
url:url, async:true,
complete: function (req) {
getOptions(req, $("#handle_user").get(0));
}
});
function getOptions(req, obj) {
// 要重新插入option的select
obj.options.length = 0;
obj.add(new Option("--- 請選擇 ---", ""));
var xmlDoc = req.responseXML.documentElement;
try {
var selectArr = xmlDoc.getElementsByTagName("select");
for (var i = 0; i < selectArr.length; i++) {
// value
var value = selectArr[i].childNodes[0].firstChild.nodeValue;
// label
var label = selectArr[i].childNodes[1].firstChild.nodeValue;
var option = new Option(label, value);
obj.add(option);
}
} catch(e) {
}
}
[/color][/color]