隐藏'清除'按钮,直到'按钮点击

Hide a 'Clear' button until the 'Apply' button clicked

本文关键字:按钮 直到 清除 隐藏      更新时间:2023-09-26

我有一个表单,在我的过滤器下面有按钮(应用过滤器&清除过滤器)当点击"应用"按钮时,我试图显示"清除",当点击"清除"按钮时隐藏"清除"按钮。

下面的代码表示我的表:

<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">

不使用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>

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

我不认为这可以不使用javascript/jquery使用jquery。这是你要找的吗?

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

看看我在你的html里做了什么

已经决定,虽然隐藏'Clear'按钮将是一个'很好的',它应该显示在任何时候,并可能在未来的修复隐藏它一旦应用程序启动和运行。

感谢所有的评论/帮助。