在你-1之前,这是一个如此简单的问题,因为我花了一段时间搜索并找不到它。我有什么是5个选择框。每个结果取决于之前选择的内容。没有提交按钮。我只需要根据在上一个框中选择的内容进行更改,到目前为止我已经拥有了该功能。哦,结果正在从数据库中提取。问题在于,当您在选项1中选择一个选项时,会出现框2选项,但当您再次选择框1中的选项时,它们的选项将叠加在其他选项上。当它再次改变时,我需要他们清除。我会张贴我拥有的js,如果你还需要其他的东西,就问问。使用javascript更改选择选项
p.s.即时通讯使用php-mysql的选项。 ps.s.s这个网站必须在明天完成,所以即使有点急。请不要浪费时间告诉我这是一个愚蠢的问题,或者不是。
在此先感谢您的帮助。
$(function() { //When the page is finished loading run this code
$('#country').change(function() {
$.ajax({
url: "<!--Base url taken out-->/discovery/aLoad",
success: function (data) {
eval(data);
},
error: function() {
alert('failed');
},
data: {
country: getSelectValues('#country')
},
type: 'POST'
});
});
});
function changeSearchBar (newBar) {
//remove the crap
function ClearOptions(country)
{
document.getElementById('country').options.length = 0;
}
for (var i = 0; i <= newBar.length; i++) {
newBar[i].id = newBar[i][0];
newBar[i].name = newBar[i][1];
$('#group').append(
$('<option></option>').attr('value', newBar[i].id).text(newBar[i].name)
);
}
}
function getSelectValues (sId) {
var str = "";
$(sId +" option:selected").each(function() {
str += $(this).val() + ",";
});
return str.replace(/.$/g, '');
}
您的ClearOptions功能看起来很不错,但我没有看到它在哪里调用它。它被定义为changeSearchBar,但从未被调用。我想如果你在for循环之前调用它,你应该没问题。 – Zoidberg 2012-02-28 02:49:11