繁体   English   中英

通过javascript ASP.NET MVC下拉列表调用按钮

[英]calling a button through javascript ASP.NET MVC dropdown list

我想通过对下拉列表更改做出响应的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函数不提交下拉列表更改中的按钮。

选择器$("#YearTermList")找不到任何内容,因为标记中没有id YearTermList

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM