我有一个带有两个单选按钮(购买,租赁)和两个选择列表(最低价格,最高价格)的表格(如下)。
选择“购买”单选按钮时,它将调用其JavaScript,并且下拉选项将更改为“购买价格”(100000英镑,200000英镑等)。选择“租用”单选按钮时,它将再次调用它的JavaScript,并显示“租用价格”(每周250英镑,每周500英镑等)。
以下JavaScript:
if (BuyRent=='buy') {
document.SearchForm.MaxPrice.options[0]=new Option("Price (Max)","150000000");
document.SearchForm.MaxPrice.options[1]=new Option("\u00A3100,000","100000");
document.SearchForm.MaxPrice.options[2]=new Option("\u00A3200,000","200000");
document.SearchForm.MinPrice.options[0]=new Option("Price (Min)","0");
document.SearchForm.MinPrice.options[1]=new Option("\u00A3100,000","100000");
document.SearchForm.MinPrice.options[2]=new Option("\u00A3200,000","200000");
} else if (BuyRent=='rent') {
while (document.SearchForm.MaxPrice.options.length>0) {
document.SearchForm.MaxPrice.options[0]=null;
}
while (document.SearchForm.MinPrice.options.length>0) {
document.SearchForm.MinPrice.options[0]=null
}
document.SearchForm.MaxPrice.options[0]=new Option ("Price (Max)","9999999");
document.SearchForm.MaxPrice.options[1]=new Option("\u00A3250","250");
document.SearchForm.MaxPrice.options[2]=new Option("\u00A3500","500");
document.SearchForm.MinPrice.options[0]=new Option("Price (Min)","0");
document.SearchForm.MinPrice.options[1]=new Option("\u00A3250","250");
document.SearchForm.MinPrice.options[2]=new Option("\u00A3500","500");
}
有没有一种方法可以告诉每个选项在提交表单时记住其选择?
最佳答案
如果要提交表单,则可能需要将值存储在hidden
HTML元素中。
关于javascript - 保持选择状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4200446/