菜单

行使js获取下拉框中所选的值

2019年8月24日 - Bootstrap

应用js获取下拉框中所选的值,js获取下拉框所选

于今的供给是:下拉框中假诺选项加盟商让其接二连三选择高校,即使采取平台管理员则无需选择院校。掩盖选用下拉列表。

挑选枚举值:

/// <summary>
/// 平台角色
/// </summary>
public enum AdministratorRole
{
 [Display(Name = "平台管理员")]
 PlatformAdministrator = 1,
 [Display(Name = "加盟商")]
 JoiningTrader = 10
}

代码:

<div class="form-group">
  @Html.LabelFor(x => x.AdministratorRole, new { @class = "col-sm-2 control-label" })
  <div class="col-sm-8">
   @Html.EnumDropDownListFor(x => x.AdministratorRole, new { @class = "form-control", onChange = "showSchool(this.value)", placeholder = Html.DisplayNameFor(x => x.AdministratorRole) })
  </div>
  <div class="col-sm-2">
   <div class="help-block">@Html.ValidationMessageFor(x => x.AdministratorRole)</div>
  </div>
 </div>
 <div class="form-group" style="display:none" id="schoolSelect">
  @Html.LabelFor(x => x.SchoolId, new { @class = "col-sm-2 control-label" })
  <div class="col-sm-8">
   @Html.DropDownListFor(x => x.SchoolId, Model.Schools, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.SchoolId) })
  </div>
  <div class="col-sm-2">
   <div class="help-block">@Html.ValidationMessageFor(x => x.SchoolId)</div>
  </div>
 </div>

   
先让这个学院列表隐蔽,style=”display:none”;效果和下图一律。我们使用下拉框的onChange事件来让其实行设定的点子showSchool(),那中间的参数是大家选用的值,this代表的AdministratorRole。

js代码:

 <script type="text/javascript"> 
 function showSchool(v){  
  if (10 == v) {
   document.getElementById("schoolSelect").style = "display:inline";
  } else {
   document.getElementById("schoolSelect").style = "display:none";
  }
 }
</script>

那般就足以了。

效果:

图片 1

如上正是本文的全体内容,希望对我们享有辅助,同一时候也可望多多支持帮客之家!

http://www.bkjia.com/Javascript/1176538.htmlwww.bkjia.comtruehttp://www.bkjia.com/Javascript/1176538.htmlTechArticle利用js获取下拉框中所选的值,js获取下拉框所选
未来的急需是:下拉框中若是选项加盟商让其继续选择学校,即使选拔平台管理员则不需…

昨天的需假若:下拉框中纵然选拔加盟商让其继续选择学院,纵然选用平台助理馆员则无需选择学院。遮掩选取下拉列表。

选拔枚举值:

/// <summary>
/// 平台角色
/// </summary>
public enum AdministratorRole
{
 [Display(Name = "平台管理员")]
 PlatformAdministrator = 1,
 [Display(Name = "加盟商")]
 JoiningTrader = 10
}

代码:

<div class="form-group">
  @Html.LabelFor(x => x.AdministratorRole, new { @class = "col-sm-2 control-label" })
  <div class="col-sm-8">
   @Html.EnumDropDownListFor(x => x.AdministratorRole, new { @class = "form-control", onChange = "showSchool(this.value)", placeholder = Html.DisplayNameFor(x => x.AdministratorRole) })
  </div>
  <div class="col-sm-2">
   <div class="help-block">@Html.ValidationMessageFor(x => x.AdministratorRole)</div>
  </div>
 </div>
 <div class="form-group" style="display:none" id="schoolSelect">
  @Html.LabelFor(x => x.SchoolId, new { @class = "col-sm-2 control-label" })
  <div class="col-sm-8">
   @Html.DropDownListFor(x => x.SchoolId, Model.Schools, new { @class = "form-control", placeholder = Html.DisplayNameFor(x => x.SchoolId) })
  </div>
  <div class="col-sm-2">
   <div class="help-block">@Html.ValidationMessageFor(x => x.SchoolId)</div>
  </div>
 </div>

   
先让这个学校列表遮蔽,style=”display:none”;效果和下图一律。大家使用下拉框的onChange事件来让其实施设定的方法showSchool(),那中间的参数是我们选用的值,this代表的AdministratorRole。

js代码:

 <script type="text/javascript"> 
 function showSchool(v){  
  if (10 == v) {
   document.getElementById("schoolSelect").style = "display:inline";
  } else {
   document.getElementById("schoolSelect").style = "display:none";
  }
 }
</script>

那般就足以了。

效果:

图片 2

上述正是本文的全部内容,希望对大家持有帮忙,同期也希望多多协理脚本之家!

你可能感兴趣的篇章:

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图