簡體   English   中英

檢查下拉列表中的選定值

[英]check the selected value in drop down list

我有以下下拉列表。 在將數據保存到模塊之前,如何檢查所選值? 我想在設置“鄰居”下拉列表的值時使用選定的值。

        @Html.DropDownListFor(model => model.City, new SelectList(
          new List<Object>{
               new { value = "Abha", text = "Abha" },
               new { value = "Al Qunfudhah", text = "Al Qunfudhah" },
               new { value = "Al-Kharj", text = "Al-Kharj" },
               new { value = "Al-Ahsa", text = "Al-Ahsa" },
               new { value = "Buraidah", text = "Buraidah" },
               new { value = "Dammam", text = "Dammam" },
               new { value = "Ha'il", text = "Ha'il"},
               new { value = "Hafar Al-Batin", text = "Hafar Al-Batin" },
               new { value = "Jazan", text = "Jazan" },
               new { value = "Jeddah", text = "Jeddah" },
               new { value = "Jubail", text = "Jubail" },
               new { value = "khobar", text = "khobar" },
               new { value = "Khamis Mushait", text = "Khamis Mushait" },
               new { value = "Mecca", text = "Mecca" },
               new { value = "Medina", text = "Medina" },
               new { value = "Najran", text = "Najran" },
               new { value = "Qatif", text = "Qatif" },
               new { value = "Riyadh", text = "Riyadh" },
               new { value = "Tabuk", text = "Tabuk" },
               new { value = "Ta'if", text = "Ta'if" },
               new { value = "Yanbu", text = "Yanbu" }
          },"value", "text", "Jeddah"))

        @Html.ValidationMessageFor(model => model.City)
    </div>
</div> 

使用jQuery,您可以嘗試

$('#City').val();

如果您不使用jQuery,則使用普通的javascript方法是

var element = document.getElementById("City");
var strVal = element.options[element.selectedIndex].value;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM