如何将一个或多个事件添加到以这种方式添加的下拉列表中
@ Html.DropDownList(“List”)?
答案 0 :(得分:2)
如果你习惯使用jQuery:,试试这个:
$("#DropDownListID").change(function () {
var selectedValue = $(this).val();
//Do whatever you want to do on selection changes here
});
答案 1 :(得分:1)
@Html.DropDownList("PageItemDD", (SelectList)ViewBag.itemsPerPage, new { onchange = "document.location.href = '/List?ipp=' + this.options[this.selectedIndex].value;" })
new { onchange = "document.location.href = '/List?ipp=' + this.options[this.selectedIndex].value;" }
部分(DropDownList的第3个参数)是html属性。在这种情况下,我有一个onchange
来覆盖此页面:/List?ipp= the value of the dropdownlist