【问题标题】:How to reset the checkbox, search text box and select list?如何重置复选框、搜索文本框和选择列表?
【发布时间】:2016-10-20 22:39:18
【问题描述】:

这是我的html页面:

<form id="userworklog"  action="#" method="post">
    <div id="userlogs" class="userlogs">
        <table id="worklog">
            <tr>
                <th>Strt date</th>
                <th>Projects</th>
                <th>Charge# Field</th>
                <th>Employee Name</th>
            </tr>
            <tr>
                <td>
                    <input type= "date" id="startdate" name="startdate"  class="required">
                </td>
                <td>
                    <input type="text" name="SearchBox" id="SearchBox" placeholder="Search...." />  
                    <br /> 
                    <select  id="projectsList" class="textFld" multiple="multiple"/>
                </td>
                <td>
                    <input type="text"  id="comboBox" placeholder="Search.." />
                    <ul id="userList"  class="nobull" style="width: 300px; height: 80px;list-style: none; overflow: auto">
                </td>
            </tr>
        </table>

我有提交和重置按钮。我们正在动态加载数据并填充到 html。当我提交重置输入“开始日期”只是重置。要重置我使用 jQuery 的检查列表

$("#reset").on("click", function () {
    $("#checkbox").attr("checked", false);
});

我可以重置项目和员工的搜索。除非我按进入项目列表数据在 html 中没有查看

【问题讨论】:

  • 不要使用id选择器重置复选框的值。

标签: javascript jquery


【解决方案1】:
$("#reset).on("click", function(){
    $('#checkbox').prop('checked', false);
})

这应该将复选框重置为 false。 也请看这里:Setting "checked" for a checkbox with jQuery?

【讨论】:

    【解决方案2】:

    要重置复选框字段,请在 jquery 下方使用,

    $('input:checkbox').removeAttr('checked');
    

    要重置选择列表,请使用以下 jquery,

    $("#projectsList").prop('selectedIndex',0);
    

    要重置搜索文本框,请使用下面的 jquery,

    $("#SearchBox").val('');
    

    【讨论】:

    • 感谢您的帮助。这对我有帮助。
    • 但是我有一个问题,例如:如果
    • 感谢搜索... 1.AB 2.BC 3.gvj 如果我搜索 a..如果我单击重置...,表格将显示为 1.AB。直到我在搜索中按 Enter ......它会这样显示。搜索... 1.AB 2.BC 3.gvj 你的帮助。这对我有帮助。但我有一个问题,例如:如果
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2022-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    相关资源
    最近更新 更多