[英]Appending to a certain element, that also doesn't have a certain class
I have a table, that may have rows with a hidden
class: 我有一个表,可能有带有hidden
类的行:
<table id="sortme">
<tr>
<td>
<input type="hidden" name="pr" value="1" />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="pr" value="7" />
</td>
</tr>
<tr>
<td class="hidden">
<input type="hidden" name="pr" value="4" />
</td>
</tr>
I have function that sorts the whole table according to the input
: 我有根据input
对整个表进行排序的功能:
<script>
$(function() {
$('#sortme tr:has(input[name="pr"])').sort(function(a, b) {
return 1 * $(a).find("input[name='pr']").val() - 1 * $(b).find("input[name='pr']").val();
}).appendTo('#sortme');
});
</script>
I want to sort only the rows without hidden
class. 我只想对没有 hidden
类的行进行排序。
I tried adding: 我尝试添加:
|| tr.!(hasClass("hidden"))
To the function this way: 对于这种方式的功能:
<script>
$(function() {
$('#sortme tr:has(input[name="pr"]) || tr.!(hasClass("hidden"))').sort(function(a, b) {
return 1 * $(a).find("input[name='pr']").val() - 1 * $(b).find("input[name='pr']").val();
}).appendTo('#sortme');
});
</script>
But that's probably not the correct syntax. 但这可能不是正确的语法。
I'm not even sure if I should it over there, or at the appendTo
part. 我什至不确定是应该在那边还是在appendTo
部分。
How should it be? 应该怎么办
Edit: 编辑:
Updated code: 更新的代码:
I sort first by class (not-hidden), and then by numeber (lowest first): 我首先按类(不隐藏)排序,然后按数字(最低的优先级)排序:
$('#sortme tr:has(input[name="pr"]):not(.hidden)').sort(function(a, b) {
return 1 * $(a).find("input[name='pr']").val() - 1 * $(b).find("input[name='pr']").val();
}).appendTo('#sortme');
$('#sortme tr:has(input[name="pr"]).hidden').sort(function(a, b) {
return 1 * $(a).find("input[name='pr']").val() - 1 * $(b).find("input[name='pr']").val();
}).appendTo('#sortme');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.