首页 > 解决方案 > 如何根据 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>

标签: asp.net-core

解决方案


您似乎想根据所选选项显示和隐藏 div,如果是这样,您可以使用更改功能并更改脚本,如下所示:

<script>
    $(function () {
        $("#show").change(function () {
            var option = $(this).val();
            if (option == "xxx") { 
                $("#me").show();
            } else {
                $("#me").hide();
            }
        });
    });
</script>

推荐阅读