asp.net-core - 如何根据 ASP.Net Core 中的 DropDownList 选择显示和隐藏 TextBox?
问题描述
当在 DropDownList 中选择了 Custmor 项(选项)时,名为(why)的 TextBox 将可见,否则 TextBox 将在 ASP.Net Core 中隐藏当在 DropDownList 中选择 Custmor 项(选项)时,文本框可见我怎样才能将其更改为不可见?在此处输入代码 custmor 帐户
</select>
</div>
<div class="form-group">
<label asp-for="Axe" class="control-label"></label>
<select asp-for="Axe" class="form-control">
<option>géographique</option>
<option>démographique</option>
<option>psycologique</option>
<option>comportementale</option>
</select>
</div>
<div class="form-group" id="me">
<label asp-for="why" class="control-label"></label>
<input asp-for="why class="form-control" />
<span asp-validation-for="why" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
我试过这个脚本但不起作用
<script src="~/lib/jquery/dist/jquery.js"></script>
<script>
$(function () {
$("#show").click(function () {
$("#me").show();
$("#he").hide();
});
});
</script>
解决方案
您似乎想根据所选选项显示和隐藏 div,如果是这样,您可以使用更改功能并更改脚本,如下所示:
<script>
$(function () {
$("#show").change(function () {
var option = $(this).val();
if (option == "xxx") {
$("#me").show();
} else {
$("#me").hide();
}
});
});
</script>
推荐阅读
- xml - 是否可以使用 Go 解析完整的 CCDA xml 文件?
- r - 调度 R 脚本
- javascript - backgroundColor 不会重新渲染 - React
- python - 计数字符串出现次数/枚举列表中的出现次数
- uwp - UWP 应用:MessageDialog ShowAsync 在 LaunchUriForResultsAsync 的 OnActivated 中不起作用
- flask-socketio - Flask-socketIO + Kafka 作为后台进程
- java - Java 正则表达式匹配 UTF-8 字符串(无副本)
- powershell - “找不到路径的一部分”是什么意思?
- reactjs - 当用户在下拉组件中选择新选项时无法传递正确的值
- c# - 脚手架后的迁移问题。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)