- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要更改 2 div
的可见性方面的帮助根据 DropDownListFor 中所选值的元素。
比方说,dropDown 中有值“One”、“Two”和“Three”。
div
id="time"
当选择“一”或“二”的值并隐藏时 div
id="fromTo"
div
id="fromTo"
并隐藏div
id="time"
。 这是我目前拥有的代码:
<div class="form-group">
@Html.LabelFor(model => model.I_Uloha, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.UlohaString, (SelectList)ViewBag.Tasks, new { @class = "form-control"})
@Html.ValidationMessageFor(model => model.I_Uloha, "", new { @class = "text-danger" })
</div>
</div>
<div id="time" class="form-group">
@Html.LabelFor(model => model.Zataz, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Zataz, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Zataz, "", new { @class = "text-danger" })
</div>
</div>
<div id="fromTo">
<div class="form-group">
@Html.LabelFor(model => model.D_Zac, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.D_Zac, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.D_Zac, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.D_Kon, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.D_Kon, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.D_Kon, "", new { @class = "text-danger" })
</div>
</div>
</div>
最佳答案
您需要使用 jQuery show()
和 hide()
方法来更改 View 页面中 div
元素的可见性,具体取决于下拉菜单列出这样的值:
<script type="text/javascript">
$(document).ready(function () {
$('#UlohaString').change(function () {
var ddlValue = $(this).val();
if (ddlValue == "One" || ddlValue == "Two")
{
// show time div, hide fromTo div
$('#time').show();
$('#fromTo').hide();
}
else if (ddlValue == "Three")
{
// show fromTo div, hide time div
$('#fromTo').show();
$('#time').hide();
}
});
});
</script>
请注意,如果$(this).val()
,则可以使用var ddlValue = $(this).find(':selected').text()
在这里不起作用。
引用:
How to hide and show div in asp.net mvc 5 using dropdownlist change event
关于javascript - 根据 DropDownListFor 显示/隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45207169/
我有一个 DropDownListFor 组件,它有一个从数据库获取值的读取操作。但是,我想根据另一个 DropDownListFor 的值过滤这些值。 这是具有过滤器值的 DropDownListF
我正在为语言生成一个下拉列表。我想将该列表的特定项目设为 selected。这是查看页面代码: @{var languageList = new List(); var cultures =
我有一个绑定(bind)到模型成员的 DropDownListFor 以及可供选择的项目列表。绑定(bind)到这个成员有效,但我似乎无法弄清楚的是如何在页面加载时显示模型的当前值。 查看 @Html
我已经看到许多关于 DropDownListFor 验证的类似问题和答案,但我还没有看到我的特定问题。 这是我的 html 助手。 VB: @Html.DropDownListFor(Function
我有一个带有 BootStrap 的 Html.DropDownListFor,它不像我表单中的 Html.TextBoxFor 那样左对齐。我试过“向左拉”和“向左文本”都没有运气。当我使用开发人员
我发誓我在尝试从静态状态列表填充 DropDownList 时遇到了麻烦。我更希望通过 EntityFramework 从数据库中预先填充此列表。 我的 RegisterViewModel publi
我在输入表单中有其他字段和下拉列表。他们都验证得很好。即使没有正确验证前端的两个元素仍然可以在帖子中正确地建模绑定(bind)。我不完全确定他们为什么不验证。这是设置: View 模型 public
我知道已经有很多类似的问题,但我花了几个小时试图解决这个问题,其他答案似乎都没有帮助! 我只想使用 MVC 在下拉列表中显示字符串列表。这真的有那么难吗?我没有“文本”和“值”分隔(尽管 MVC 似乎
我想在 HTML 助手中添加扩展方法来生成这样的选择和选项 Andorra United Arab Emirates Afghanistan 选项有一个数据域属性,我可以这样使用它 @Html.Dr
所以,我得到了一个在我看来看起来像这样的 DropdownListfor: @Html.DropDownListFor(m => m.ProductCategory, new SelectList(M
首先,我是 .NET MVC 的新手,虽然我以前使用过一般的 MVC 想法。我正在使用 .NET MVC4 和 CodeFirst 使用 Entity Framework 。 我正在尝试向“创建” V
我正在尝试将数据从我的数据库检索到 HTML,而不是检索到 Html.DropDownListFor,但我无法检索到标记。 NewCustomerViewModel public class
我有一个 departmentID 的下拉列表,它根据在 DepartmentCategoryID 中选择的内容进行填充,但是如果它留空,我将无法进行验证。它或所有其他的都有效,但这是以不同的方式完成
我想知道是否有人可以帮助我解决我面临的问题。我正在尝试使用 Razor 在 DropDownListFor 上创建搜索。 private List LoadStockitems() { Lis
我已经搜索了好几个小时并尝试了所有的建议。我想我缺少一些基本概念。我想使用模型而不是 ViewBag,并且我在回发的模型中设置了选定的项目/值。 我正在 cshtml 中设置一个 ddl 和 acti
这是我的 View 模型: public class EntityViewModel { [Required(ErrorMessage = "Title is required")]
我正在尝试填充 DropDownListFor数据库中的项目,但是当我尝试运行该程序时,它给了我错误 Object reference not set to an instance .就像方法(从数据
我有以下设置我的下拉菜单到荒谬的宽度: @Html.DropDownListFor(x => x.TypeId, new SelectList(Model.Type, "TypeId", "Ty
一直在尝试多种方法来更改 DropDownListFor 元素的样式。要么我做错了什么,要么有什么东西压倒了它。我已经尝试在 View 元素和 CSS 中更改它。但没有成功。 查看: @H
我显然在理解 JS 方面遇到了问题。我是新手,我正在尝试让它适用于以下用例: If "Healthcare" is selected from the "discipline" dropdown th
我是一名优秀的程序员,十分优秀!