<script type="text/javascript">
$(document).ready(function(){
$("select#type").attr("disabled","disabled");
$("select#model").attr("disabled","disabled");
$("select#category").change(function(){
$("select#type").attr("disabled","disabled");
$("select#type").html("<option>Please wait...</option>");
var id = $("select#category option:selected").attr('value');
$.post("../select_type.php", {id:id}, function(data){
$("select#type").removeAttr("disabled");
$("select#type").html(data);
});
});
$("select#type").change(function(){
$("select#model").attr("disabled","disabled");
$("select#model").html("<option>Please wait...</option>");
var id2 = $("select#type option:selected").attr('value');
$.post("../select_model.php", {id2:id2}, function(data){
$("select#model").removeAttr("disabled");
$("select#model").html(data);
});
});
$("select#model").change(function(){
var cat = $("select#category option:selected").attr('value');
var type = $("select#type option:selected").attr('value');
var model = $("select#model option:selected").attr('value');
if(cat>0 && type>0 && model >0)
{
var model = $("select#model option:selected").html();
var type = $("select#type option:selected").html();
$("#result").html('<br>Your choice: ' + type + ' ' + model + '.');
}
else
{
$("#result").html("<br>Error! You did not select everything!");
}
return false;
});
});
这是我的代码。它几乎正常工作......我的问题是,每当我进入选择菜单的第3级,然后将第一级更改为默认值时,其他2级将不会更改为不可用且仍可选择。我该如何扩展代码?