【问题标题】:Hide a 'Clear' button until the 'Apply' button clicked隐藏“清除”按钮,直到单击“应用”按钮
【发布时间】:2014-05-03 13:41:36
【问题描述】:

我有一个表单,其中我的过滤器下方有按钮(应用过滤器和清除过滤器)我试图在单击“应用”按钮时显示“清除”并在单击时隐藏“清除”按钮。

如果我的桌子有什么,下面的代码:

<dl class="filterlist" style="margin-top: 0px">
        <dt>
            <label for="Environment">Environment</label>
        </dt>
        <dd>
            @Html.DropDownList("EnvironmentDD", (IEnumerable<SelectListItem>)ViewBag.Environment, "- - All Environments - -", 
                new { @class = "ddstyle", @id = "Environment", @title = "Filter the table below by environment." })
        </dd>
        <dt>
            <label for="Product">Product</label>
        </dt>
        <dd>
            @Html.DropDownList("ProductDD", (IEnumerable<SelectListItem>)ViewBag.Product, "- - All Products - -", 
                new { @class = "ddstyle", @id = "Product", @title = "Filter the table below by product." })
        </dd>
        <dt>
            <label for="TestType">Test Type</label>
        </dt>
        <dd>
            @Html.DropDownList("TestTypeDD", (IEnumerable<SelectListItem>)ViewBag.TestType, "- - All Test Types - -", 
                new { @class = "ddstyle", @id="TestType", @title="Filter the table below by test type." })
        </dd>
        <dt>
            <label for="TestScenario">Test Scenario</label>
        </dt>
        <dd>
            @Html.DropDownList("ScenarioDD", (IEnumerable<SelectListItem>)ViewBag.Scenario, "- - All Test Scenarios - -", 
                new { @class = "ddstyle", @id="TestScenario", @title="Filter the table below by test scenario." })
        </dd>
        <dt>&nbsp;</dt>
        <dd>
            <button class="butstyle" id="ApplyFilter" type="submit" title="Click to apply any filters selected above.">
                Apply Filter(s) <i class="fa fa-filter"></i>
            </button>
            <button class="butstyle" id="ClearFilters" title="Click to reset any filters set." style="display:none">
                Clear Filter(s) <i class="fa fa-eraser"></i>
            </button>
        </dd>
    </dl>

我该怎么做或者最好的方法是什么,因为我似乎无法理解它。我正在使用 HTML5 和 MVC5。

默认情况下,按钮设置为:

style="display:none">

【问题讨论】:

  • 如果可能的话,我宁愿在没有 java/jquery 的情况下这样做
  • 您可以使用“复选框破解”。 link
  • 有人可以为此提供 jquery,因为我发现使用它是最好的选择。 AJ提供的那个好像不行。即使在他们提供的小提琴中
  • 让我看看我是否理解正确。您希望默认显示“应用”按钮,当单击该按钮时,将其隐藏并显示“清除”按钮。那么,当点击“清除”按钮时,隐藏它?这是 AJ 代码的略微修改版本(删除了 1 行)jsfiddle.net/x3PMX/4。或者,如果您不想隐藏“应用”按钮:jsfiddle.net/x3PMX/5
  • @RobinvdA - 感谢您的回复。不会在页面加载时显示“应用”按钮,然后如果用户从我的 4 个下拉列表之一中选择一个过滤器并单击“应用”按钮,则会在“应用”按钮旁边显示一个“清除”按钮然后如果单击“清除”按钮,则将其隐藏

标签: javascript jquery html asp.net-mvc-5


【解决方案1】:

已决定虽然隐藏“清除”按钮将是“很高兴”,但它应始终显示,并且可能在应用程序启动并运行后隐藏它。

感谢所有 cmets/帮助。

【讨论】:

    【解决方案2】:

    没有 JQuery:

    <button onclick="document.getElementById('ClearFilters').style.display='block';" class="butstyle" id="ApplyFilter" type="submit" title="Click to apply any filters selected above.">
        Apply Filter(s) <i class="fa fa-filter"></i>
    </button>
    <button onclick="document.getElementById('ClearFilters').style.display='none';" class="butstyle" id="ClearFilters" title="Click to reset any filters set." style="display:none">
        Clear Filter(s) <i class="fa fa-eraser"></i>
    </button>
    

    唯一的另一种方法是在按下按钮时重新加载页面并检查按下了哪个按钮...

    【讨论】:

    • 这是我正在寻找的,但它第一次工作(显示清除按钮)然后将其删除,但是当我再次尝试单击应用按钮时,清除按钮闪烁然后隐藏。
    • 那肯定是有其他原因造成的,因为 fiddle 有效...
    【解决方案3】:

    我认为不使用 javascript/jquery 就无法做到这一点。使用 jQuery .. 这就是你要找的东西

    $("#ApplyFilter").click(function(){
    $("#ClearFilters").toggle();
        $(this).toggle();
    });
    $("#ClearFilters").click(function(){
    $("#ApplyFilter").toggle();
        $(this).toggle();
    });
    

    检查这个fiddle我是用你的html制作的。

    【讨论】:

    • 您显然没有阅读他关于“如果可能的话,我宁愿在没有 java/jquery 的情况下这样做”的评论。
    • @AnanthanUnni :我在回答中提到过,没有脚本就不可能达到要求!还是您对提出问题的用户的评论?
    • @AnanthanUnni:好的..但这应该发布到问题中。
    • @Antony:这有帮助吗?
    • 感谢您的回复,但是当我检查您提供的小提琴时它不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多