<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")