代码之家  ›  专栏  ›  技术社区  ›  MrM

如何在Firefox刷新(F5)时重置为默认下拉列表选项?

  •  11
  • MrM  · 技术社区  · 14 年前

    这就是我目前所拥有的。

    <%string ddlVal = ""%>
    <select id="detailSelect" name="DetailSelect">
        <option <%if (ddlVal == "") { Response.Write("selected = &quot;selected&quot;"); } %> value="" >--Choose One--</option>
        <option <%if (ddlVal == "Building") { Response.Write("selected = &quot;selected&quot;"); } %> value="Building">Building</option>
        <option <%if (ddlVal == "Contents") { Response.Write("selected = &quot;selected&quot;"); } %> value="Contents">Contents</option>
    </select>
    

    2 回复  |  直到 14 年前
        1
  •  36
  •   Philip Kirkbride    7 年前

    autocomplete="off" <select> 标签。这是firefox中的一个已知问题,记住您的下拉选择。

        2
  •  0
  •   Saif    8 年前

    非常简单的解决方案。 首先编写jquery代码。

    $(document).ready(function () {
        $('#originCountry').val(0);
    });
    

    在MVC Razor视图中

    @Html.DropDownList("originCountry", new SelectList(ViewBag.countriesList, "CountryId", "CountryName"), "Please select country", new { @class = "form-control", @onchange = "javascript:GetOriginCities(this.value);", @required = "required" })