function filterRows(statusName) {
$("#mainTable tbody tr."+statusName).hide();
}
它隱藏了名爲statusName
的類的行。如何隱藏只有沒有的行?隱藏沒有某個類的表格行
function filterRows(statusName) {
$("#mainTable tbody tr."+statusName).hide();
}
它隱藏了名爲statusName
的類的行。如何隱藏只有沒有的行?隱藏沒有某個類的表格行
$("#mainTable tbody tr:not(."+statusName + ')').hide();
function filterRows(statusName) {
$("#mainTable tbody tr."+statusName).siblings().hide();
}
使用.hasClass()
財產
$("#mainTable tbody tr").map(function(){
if(!$(this).hasClass('statusName'))
{
$(this).hide();
}
});
或簡單:
$('#mainTable tbody tr').each(function() {
$(this).not('.selected').hide()
});
我已經爲此創建了一個快速POC。這可以給你一個關於如何根據你的需要定製它的想法。您可以直接複製以下代碼並在瀏覽器中執行以查看結果。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MVCDemoApp.Default" %>
<!DOCTYPE html>
<html>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<head runat="server">
<title></title>
<style>
.header
{
font-family: Verdana;
font-size: large;
background-color: Gray;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="widt: 100%" id="mainTable">
<tr class="header">
<td>
Head
</td>
</tr>
<tr>
<td>
No Class
</td>
</tr>
<tr class="header">
<td>
Header Class
</td>
</tr>
</table>
</div>
</form>
</body>
<script>
/*
//Hides the rows with classes
$('table tr[class="header"]').hide();
*/
//hides the rows without classes
$('table tr[class!="header"]').hide();
</script>
</html>
-1:這裏沒有理由使用屬性選擇器。另外,http://www.jsfiddle.net – Jamiec 2012-07-10 10:33:35
[hasClass returns a boolean!](http://api.jquery.com/hasClass/) – Jamiec 2012-07-10 09:36:54
@Jamiec現在更新。 – diEcho 2012-07-10 09:47:03
我認爲這是有效的,但它是達到要求的最複雜的方法。 (順便說一句,你的downvote不是我) – Jamiec 2012-07-10 09:47:39