gpt4 book ai didi

javascript - 表上的 jquery 过滤器第一次工作,但之后隐藏所有行

转载 作者:行者123 更新时间:2023-12-02 16:28:58 24 4
gpt4 key购买 nike

我创建了一个过滤器,仅显示包含 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>

最后是表的创建:

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

知道为什么会这样吗?感谢您的帮助...

更新

我添加了 $('tr').show(); 并且函数可以正常工作,但我如何在下拉列表中添加值以显示所有表格/取消过滤器?

最佳答案

您负责隐藏行,但您永远不会将它们显示出来。这就是为什么您的表迟早会隐藏所有行。

关于javascript - 表上的 jquery 过滤器第一次工作,但之后隐藏所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28465775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com