Javascript 表上的jquery筛选器第一次工作,但之后会隐藏所有行

Javascript 表上的jquery筛选器第一次工作,但之后会隐藏所有行,javascript,jquery,html,jquery-filter,Javascript,Jquery,Html,Jquery Filter,我已经创建了一个过滤器,只显示包含td,并且从下拉列表中选择值的行。过滤器第一次工作正常,但第二次运行时,所有行都消失了,我不知道为什么。 这是我的过滤器: $(document).ready(function(){ $('select[name=selectedName]').change(function() { $('tr').filter(function () { return $(this).find('td.userName').fi

我已经创建了一个过滤器,只显示包含
td
,并且从下拉列表中选择值的行。过滤器第一次工作正常,但第二次运行时,所有行都消失了,我不知道为什么。 这是我的过滤器:

$(document).ready(function(){
    $('select[name=selectedName]').change(function() {
        $('tr').filter(function () {
            return $(this).find('td.userName').filter(function () {
                return $(this).text().indexOf($('select[name=selectedName]').val()) == -1;
            }).length;
        }).hide();
    });
});
下拉列表:

$query = "SELECT user_name FROM users";
$result = mysql_query($query); ?>
<select name="selectedName" id="userSelected">
    <option value="" disabled selected>user name</option>
    <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
        <option value="<?php echo $line['user_name'];?>">
            <?php echo $line['user_name'];?>
        </option>
    <?php } ?>
</select>
$query=“从用户中选择用户名”;
$result=mysql\u查询($query);?>
用户名
最后是表格的创建:

    <table class="table table-bordered table-hover" ng-controller="tableCtrl">
        <thead>
        <th>user name</th>
        <th>script name</th>
        <th>cron format<span class="glyphicon glyphicon-question-sign"></span></th>
        <th>schedule last update</th>
        <th>next execution time</th>
        <th>script exec</th>
        </thead>
        <tbody ng-repeat="(user_id,script_id) in data">
            <tr ng-repeat="(script_id, cron_format) in script_id">
                <td class="userName">{{user(user_id)}}</td>
                <td class="scriptName">{{script(script_id)}}</td>
                <td class="cronFormat"><span contenteditable="true" ng-repeat="l in letters(cron_format) track by $index">{{l}}</span></td>
                <td>{{compare(user_id,script_id,cron_format)[0]}}</td> <!--[0] represents scheduler last update-->
                <td>{{compare(user_id,script_id,cron_format)[1]}}</td> <!--[1] represents next execution time-->
                <td>{{compare(user_id,script_id,cron_format)[2]}}</td> <!--[2] represents script_exec-->
            </tr>
        </tbody>
    </table>

用户名
脚本名
cron格式
计划最后更新
下次执行时间
脚本执行器
{{user(user_id)}
{{script(script_id)}
{{l}
{{比较(用户id、脚本id、cron格式)[0]}
{{比较(用户id、脚本id、cron格式)[1]}
{{比较(用户id、脚本id、cron格式)[2]}
知道为什么会这样吗?谢谢你的帮助

更新


我添加了
$('tr').show()和函数工作,除了,如何在下拉列表中添加值以显示所有表/取消筛选器?

您负责隐藏行,但从不将它们显示回来。这就是为什么您的表迟早会使所有行都不可见。

在调用
.filter()
之前调用
.show()
方法。