如何重置复选框、搜索文本框和选择列表

How to reset the checkbox, search text box and select list?

本文关键字:选择 列表 文本 搜索 何重置 复选框      更新时间:2023-09-26

这是我的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

中查看
$("#reset).on("click", function(){
    $('#checkbox').prop('checked', false);
})

这会将复选框重置为false。请也看看这里:设置"已检查"jQuery的复选框?

要重置jquery下面的复选框字段,

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

重置选择列表使用下面的jquery,

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

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

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