<select class="select" size="1" name="teacher" id="teacher"> <option value="">请选择教师</option> @{ foreach (var teach in ViewBag.teacherlist) { <option value="@teach.id" data-username="@teach.username" data-userid="@teach.user_id">@teach.realname_cn</option> } } </select>
JS 取值
第一种取值
$('#select1').find("option:selected").attr("自定义属性")
"teachername": $('#teacher').find("option:selected").text(), 取名称
"teacherid": $('#teacher').val(),
"teacheruserid": $('#teacher').find("option:selected").attr("data-userid"),
"teacherusername": $('#teacher').find("option:selected").attr("data-username")
第二种取值
如果你的属性定义的是data-xxx,那么直接
$('#select1').find("option:selected").data("xxx");
$('#teacher').find("option:selected").data("userid")