如果选项为no,则需要条件下拉菜单,否则,只有其他选项出现,否则必须为null [英] Conditional dropdown is needed if the option is no then only the other should appear if not it must be null

查看:53
本文介绍了如果选项为no,则需要条件下拉菜单,否则,只有其他选项出现,否则必须为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="form-group">
            <label asp-for="son" class="control-label"></label>
            @*<input asp-for="son" class="form-control" />*@
            <select name="son" id="son">
                <option value="none" selected="selected"> -- choose one --</option>
                <option>Yes</option>
                <option>No</option>
            </select>
            <span asp-validation-for="son" class="text-danger"></span>
        </div>

如果上面的 id儿子的下拉列表为NO ,则仅出现下拉列表父亲的id .

If the above dropdown of id son is NO then only the dropdown id of father should appear.

<div class="form-group">
            <label asp-for="father" class="control-label a"></label>
            @*<input asp-for="father" class="form-control" />*@
            <select name="father" id="father">
                <option value="none" selected="selected"> -- choose one --</option>
                <option>Signed SOW Awaited</option>
                <option>Onboarding in Progress</option>

推荐答案

我认为您正在寻找的是jquery.这样,您可以检查#son是否设置为"no"(否).然后设置另一段代码来显示和隐藏.这是一段看起来很像您想要的代码:

I think what you are looking for is jquery. With this, you can check if the #son is set to "no" and then set another piece of code to show and hide. Here is a piece of code that should look a lot like what you want:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
  <div class="form-group">
    <label asp-for="son" class="control-label">Son</label>
    <select name="son" id="son">
      <option value="none" selected="selected"> -- choose one --</option>
      <option value="yes">Yes</option>
      <option value="no">No</option>
    </select>
    <div id="father" style="display: none;">
      <label asp-for="father" class="control-label a">Father</label>
      <select name="father">
        <option value="none" selected="selected"> -- choose one --</option>
        <option>Signed SOW Awaited</option>
        <option>Onboarding in Progress</option>
      </select>
    </div>
  </div>
  <script>
    $("#son").change(function() {
      if ($(this).val() === "no") {
        $("#father").show();
      } else {
        $("#father").hide();
      }
    });
  </script>
</body>

</html>

JQuery最初可能有点吓人,但我建议您坚持这样的基础知识.这也是我对JQuery所了解的全部内容.

JQuery might be a little intimidating at first, but I suggest just sticking to the basics like this. This is also pretty much all I know about JQuery.

这篇关于如果选项为no,则需要条件下拉菜单,否则,只有其他选项出现,否则必须为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆