$(document).ready(
function
(){
var
carnameSelect = $(
".carname"
).children(
"select"
);
var
cartypeSelect = $(
".cartype"
).children(
"select"
);
carnameSelect.change(
function
(){
var
carnameValue = $(this).val();
if
( carnameValue !=
""
){
if
(!carnameSelect.data(carnameValue)){
$.post(
"ChainSelect"
,{keyword:carnameValue,type:
"top"
},
function
(data){
if
(data.length != 0){
cartypeSelect.html(
""
);
$(
"<option value=''>请选择汽车类型</option>"
).appendTo(cartypeSelect);
for
(
var
i = 0;i < data.length; i++ ){
$(
"<option value =' "
+ data[i] +
" '> "
+ data[i] +
"</option>"
).appendTo(cartypeSelect);
}
cartypeSelect.parent().show();
carnameSelect.next().show();
}
else
{
cartypeSelect.parent().hide();
carnameSelect.next().hide();
}
carnameSelect.data(carnameValue,data);
},
"json"
);
}
else
{
var
data = carnameSelect.data(carnameValue);
if
(data.length != 0){
cartypeSelect.html(
""
);
$(
"<option value=''>请选择汽车类型</option>"
).appendTo(cartypeSelect);
for
(
var
i = 0;i < data.length; i++ ){
$(
"<option value =' "
+ data[i] +
" '> "
+ data[i] +
"</option>"
).appendTo(cartypeSelect);
}
cartypeSelect.parent().show();
carnameSelect.next().show();
}
else
{
cartypeSelect.parent().hide();
carnameSelect.next().hide();
}
}
}
else
{
cartypeSelect.parent().hide();
carnameSelect.next().hide();
}
});
});