溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JQuery學習筆記-JQuery的CSS DOM操作

發布時間:2020-05-23 13:56:45 來源:網絡 閱讀:677 作者:umgsai 欄目:web開發

JQuery學習筆記-JQuery的CSS DOM操作

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title></title>
		<style type="text/css">
			*{ margin:0; padding:0;}
			body {font-size:12px;text-align:center;}
			a { color:#04D; text-decoration:none;}
			a:hover { color:#F50; text-decoration:underline;}
			.SubCategoryBox {width:600px; margin:0 auto; text-align:center;margin-top:40px;}
			.SubCategoryBox ul { list-style:none;}
			.SubCategoryBox ul li { display:block; float:left; width:200px; line-height:20px;}
			.showmore { clear:both; text-align:center;padding-top:10px;}
			.showmore a { display:block; width:120px; margin:0 auto; line-height:24px; border:1px solid #AAA;}
			
			.showmore a span { padding-left:15px; background:url(img/down.gif) no-repeat 0 0;}
			
			.promoted a { color:#F50;}
		</style>
		<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
		<script type="text/javascript">
			$(function(){
				
				//測試 jQuery 樣式相關的方法. 
				
				//1. hasClass(): 某元素是否有指定的樣式
				alert($("div:first").hasClass("SubCategoryBox")); //true
				
				//2. 移除樣式
				$("div:first").removeClass("SubCategoryBox");
				
				alert($("div:first").hasClass("SubCategoryBox"));
				
				//3. 添加樣式
				$("div:first").addClass("SubCategoryBox");
				
				//4. 切換樣式: 存在, 則去除; 沒有, 則添加. 
				$(".showmore").click(function(){
					$("div:first").toggleClass("SubCategoryBox");
					return false;
				});
				
				//5. 獲取和設置元素透明度: opacity 屬性
				alert($("div:first").css("opacity"));
				
				$("div:first").css("opacity", 0.5);
				
				//6. width 和 height
				alert($("div:first").width());
				alert($("div:first").height());
				
				$("div:first").width(400);
				$("div:first").height(80);
				
				//7. 獲取元素在當前視窗中的相對位移: offset(). 
				//其返回對象包含了兩個屬性: top, left. 該方法只對可見元素有效
				alert($("div:first").offset().top);
				alert($("div:first").offset().left);
				
			});
		</script>
	</head>
	<body>
		<div class="SubCategoryBox">
			<ul>
				<li ><a href="#">佳能</a><i>(30440) </i></li>
				<li ><a href="#">索尼</a><i>(27220) </i></li>
				<li ><a href="#">三星</a><i>(20808) </i></li>
				<li ><a href="#">尼康</a><i>(17821) </i></li>
				<li ><a href="#">松下</a><i>(12289) </i></li>
				<li ><a href="#">卡西歐</a><i>(8242) </i></li>
				<li ><a href="#">富士</a><i>(14894) </i></li>
				<li ><a href="#">柯達</a><i>(9520) </i></li>
				<li ><a href="#">賓得</a><i>(2195) </i></li>
				<li ><a href="#">理光</a><i>(4114) </i></li>
				<li ><a href="#">奧林巴斯</a><i>(12205) </i></li>
				<li ><a href="#">明基</a><i>(1466) </i></li>
				<li ><a href="#">愛國者</a><i>(3091) </i></li>
				<li ><a href="#">其它品牌相機</a><i>(7275) </i></li>
			</ul>
			<div class="showmore">
				<a href="more.html"><span>顯示全部品牌</span></a>
			</div>
		</div>
	</body>
</html>

實現上面的按鈕的事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
        <style type="text/css">
            *{ margin:0; padding:0;}
            body {font-size:12px;text-align:center;}
            a { color:#04D; text-decoration:none;}
            a:hover { color:#F50; text-decoration:underline;}
            .SubCategoryBox {width:600px; margin:0 auto; text-align:center;margin-top:40px;}
            .SubCategoryBox ul { list-style:none;}
            .SubCategoryBox ul li { display:block; float:left; width:200px; line-height:20px;}
            .showmore { clear:both; text-align:center;padding-top:10px;}
            .showmore a { display:block; width:120px; margin:0 auto; line-height:24px; border:1px solid #AAA;}
             
            .showmore a span { padding-left:15px; background:url(img/down.gif) no-repeat 0 0;}
             
            .promoted a { color:#F50;}
        </style>
        <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
        <script type="text/javascript">
            $(function(){
               var $categary = $("li:gt(5):not(:last)");
               
               $categary.hide();
                 
               $(".showmore").click(function(){
            	   if($categary.is(":hidden")){
            		   $categary.show();
            		   //改變樣式
            		   $("li:contains('佳能'),li:contains('尼康')").addClass("promoted");
            		   //設置文字
            		   $(".showmore > a > span").text("顯示精簡品牌");
            		   //設置圖片
            		   $(".showmore > a > span").css("bakground", "url(img/up.gif) no-repeat 0 0");
            	   }else{
            		   $categary.hide();
            		   $("li").removeClass("promoted");
            		   $(".showmore > a > span").text("全部品牌");
            		   $(".showmore > a > span").css("bakground", "url(img/down.gif) no-repeat 0 0");
            	   }
            	   return false;
               });
            });
        </script>
    </head>
    <body>
        <div class="SubCategoryBox">
            <ul>
                <li ><a href="#">佳能</a><i>(30440) </i></li>
                <li ><a href="#">索尼</a><i>(27220) </i></li>
                <li ><a href="#">三星</a><i>(20808) </i></li>
                <li ><a href="#">尼康</a><i>(17821) </i></li>
                <li ><a href="#">松下</a><i>(12289) </i></li>
                <li ><a href="#">卡西歐</a><i>(8242) </i></li>
                <li ><a href="#">富士</a><i>(14894) </i></li>
                <li ><a href="#">柯達</a><i>(9520) </i></li>
                <li ><a href="#">賓得</a><i>(2195) </i></li>
                <li ><a href="#">理光</a><i>(4114) </i></li>
                <li ><a href="#">奧林巴斯</a><i>(12205) </i></li>
                <li ><a href="#">明基</a><i>(1466) </i></li>
                <li ><a href="#">愛國者</a><i>(3091) </i></li>
                <li ><a href="#">其它品牌相機</a><i>(7275) </i></li>
            </ul>
            <div class="showmore">
                <a href="more.html"><span>顯示全部品牌</span></a>
            </div>
        </div>
    </body>
</html>


附件:http://down.51cto.com/data/2364961
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女