[jQuery]選取器--可視否的篩選【hidden / visiable】

[jQuery]可視否的篩選【hidden / visiable】

基本語法:

  • :hidden:目前隱藏沒有顯示的
    • $('tr:hidden').fadeIn('slow');
  • :visiable:目前有顯示的
    • $('tr:visible').hide('slow');

 

範例:


<HTML>
	<HEAD>
		<Script Type="text/javascript" src="js/jQuery.js"></Script>
		<Script Type="text/javascript">
			$(document).ready(function(){
				$('#btn1').click(function(){
					$('tr:hidden').fadeIn('slow');
				});
				$('#btn2').click(function(){
					$('tr:visible').hide('slow');
				});
				$('#btn3').click(function(){
					$('#img1').fadeIn('slow');
				});
			})
		</Script>
		<style type="text/css">
			.myOdd
			{
				background-Color:pink;
			}
			.myEven
			{
				background-Color:Yellow;
			}
			.myEq
			{
				background-Color:green;
			}
		</style>
	</HEAD>
	<BODY>
		<input type="Button" id="btn1" name="btn1" value="顯示所有隱藏">
		<br />
		<input type="Button" id="btn2" name="btn2" value="隱藏所有">
		<br />
		<input type="Button" id="btn3" name="btn3" value="顯示圖">
		<br />
		<hr />
		<table border="1">
			<tr>
				<td>1,1</td>
				<td>2,1</td>
				<td>3,1</td>
				<td>4,1</td>
				<td>5,1</td>
			</tr>
			<tr style="display:none">
				<td>1,2</td>
				<td>2,2</td>
				<td>3,2</td>
				<td>4,2</td>
				<td>5,2</td>
			</tr>
			<tr>
				<td>1,3</td>
				<td>2,3</td>
				<td>3,3</td>
				<td>4,3</td>
				<td>5,3</td>
			</tr>
			<tr>
				<td>1,4</td>
				<td>2,4</td>
				<td>3,4</td>
				<td>4,4</td>
				<td>5,4</td>
			</tr>
		</table>
		<img id="img1" src="topcat.jpg" alt="topcat" style="display:none" />
	</BODY>
</HTML>

 


以下是簽名:


Visual Studio and Development Technologies
(2005~2019/6)