利用js获取下拉框中所选的值
作者:—阿辉 时间:2024-05-02 16:12:10
现在的需求是:下拉框中要是选择加盟商让其继续选择学校,要是选择平台管理员则不需要选择学校。隐藏选择下拉列表。
选择枚举值:
/// <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>
这样就可以了。
效果:
来源:http://www.cnblogs.com/netxiaohui/p/5859958.html
标签:js,下拉框
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现随机生成图片验证码详解
2023-02-26 12:20:20
![](https://img.aspxhome.com/file/2023/2/89042_0s.jpg)
PyTorch加载预训练模型实例(pretrained)
2021-02-04 15:26:11
python base64库给用户名或密码加密的流程
2021-01-30 16:30:39
纯numpy卷积神经网络实现手写数字识别的实践
2023-11-08 10:44:50
![](https://img.aspxhome.com/file/2023/7/124347_0s.png)
python3实现全角和半角字符转换的方法示例
2021-06-16 13:08:36
在laravel中使用Symfony的Crawler组件分析HTML
2023-11-17 18:54:07
Python selenium 父子、兄弟、相邻节点定位方式详解
2023-07-03 06:19:09
重新认识vue之事件阻止冒泡的实现
2024-05-10 14:18:34
![](https://img.aspxhome.com/file/2023/6/126416_0s.jpg)
Python学习pygal绘制线图代码分享
2022-12-02 10:51:48
![](https://img.aspxhome.com/file/2023/6/82956_0s.png)
卸载VS2011 Developer Preview后Sql Server2008 R2建立数据库关系图报“找不到指定的模块”错误的解决方法
2011-11-03 16:49:09
一文带你了解MySQL中的事务
2024-01-19 00:21:16
![](https://img.aspxhome.com/file/2023/4/74794_0s.png)
编译和解释的区别是什么
2022-04-13 21:52:42
一文搞懂Golang文件操作增删改查功能(基础篇)
2024-04-28 09:13:43
![](https://img.aspxhome.com/file/2023/7/134297_0s.jpg)
jQuery Easyui实现左右布局
2024-04-09 19:48:22
uniapp使用H5调试时跨域问题解决
2024-05-09 10:37:11
![](https://img.aspxhome.com/file/2023/5/126825_0s.jpg)
php Exception异常处理详解
2023-05-29 21:51:37
由Python运算π的值深入Python中科学计算的实现
2021-10-21 03:48:06
![](https://img.aspxhome.com/file/2023/0/78530_0s.png)
C#实现复制数据库 C#将A数据库数据转到B数据库
2024-01-23 11:56:09
JDBC下Idea添加mysql-jar包的详细过程
2024-01-20 10:58:18
![](https://img.aspxhome.com/file/2023/7/78957_0s.jpg)
Windows mysql命令行导入 .sql文件
2010-12-03 16:12:00