在下拉列表中获取所选项目文本时遇到问题

时间:2016-11-25 11:48:25

标签: asp.net-mvc-5

@Html.DropDownList("city",(SelectListItem)ViewBag.city,new { @class = "form-control", @onchange="fun1()"})


 $(document).ready(function fun1() {

        alert("Selected item value is " + $("#city").val() + " and Selected item 
          text is " + $("#city option:selected").text());

    });

1 个答案:

答案 0 :(得分:0)

在document.ready之外写下你的函数function fun1()。它会起作用。

相关问题