javascript - 保持选择状态

标签 javascript forms drop-down-menu selection option

我有一个带有两个单选按钮(购买,租赁)和两个选择列表(最低价格,最高价格)的表格(如下)。

选择“购买”单选按钮时,它将调用其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/

相关文章:

javascript - 如果某个值位于另一个节点中,如何每秒自动单击一个链接?

jquery - 使用 Jquery 将评论回复表单插入页面

vba - 如何在不选择列出的项目的情况下使用组合框按键事件

flutter - 在 Flutter 的 Bottom Sheet 单中创建一个下拉菜单

javascript - 如何使用验证码?

javascript - 将自动更改区域选项的国家/地区下拉列表

javascript - azure移动应用程序查询如sql语句

javascript - 在不使用表单的情况下使用 ajax 上传图像

javascript - 如何在 Microsoft Dynamics 中设置事件实体的默认类型?

javascript - jquery 停止事件时通过 ajax 提交表单