[英]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.