【问题标题】:calling a button through javascript ASP.NET MVC dropdown list通过 javascript ASP.NET MVC 下拉列表调用按钮
【发布时间】:2016-03-24 22:27:32
【问题描述】:

我想通过响应下拉列表更改的 JavaScript 函数调用 HTML 按钮。但由于某种原因,它没有找到正确的 id。

@using (Ajax.BeginForm("GetReport", "Choices",
  new AjaxOptions() {
    InsertionMode = InsertionMode.Replace,
    HttpMethod = "GET",
    UpdateTargetId = "reportResults",
  }
)) {
  @Html.DropDownList("q",(IEnumerable<SelectListItem>)ViewData["YearTermList"], htmlAttributes: new { @class = "form-control" })
  <br />
  @Html.DropDownList("ChartList", null, htmlAttributes: new { @class = "form-control" })
  <br />
  <input type="submit" style="display:none" id="ShowList" value="Search"/>
}

<script type="text/javascript">
  $(document).ready(function () {
    $("#YearTermList").change(function () {
      $("#ShowList").click();
    });
  });
</script>

JavaScript 函数不提交下拉列表更改上的按钮。

【问题讨论】:

  • 您没有任何带有id="YearTermList" 的元素(只有id="q"id="ChartList")。

标签: javascript jquery html asp.net asp.net-mvc


【解决方案1】:

选择器 $("#YearTermList") 什么也找不到,因为标记中没有 id YearTermList

您应该在要添加侦听器的位置添加id="YearTermList",或者将侦听器的选择器从#YearTermList 更改为#q#ChartList 或其他。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多