<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.high{
font-weight:bold; /* 粗體字 */
color : red; /* 字體顏色設(shè)置紅色*/
}
.another{
font-style:italic;
color:blue;
}
</style>
<!-- 引入jQuery -->
<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//獲取樣式
$("input:eq(0)").click(function(){
alert( $("p").attr("class") );
});
//設(shè)置樣式
$("input:eq(1)").click(function(){
$("p").attr("class","high");
});
//追加樣式
$("input:eq(2)").click(function(){
$("p").addClass("another");
});
//刪除全部樣式
$("input:eq(3)").click(function(){
$("p").removeClass();
});
//刪除指定樣式
$("input:eq(4)").click(function(){
$("p").removeClass("high");
});
//重復(fù)切換樣式
$("input:eq(5)").click(function(){
$("p").toggleClass("another");
});
//判斷元素是否含有某樣式
$("input:eq(6)").click(function(){
alert( $("p").hasClass("another") )
alert( $("p").is(".another") )
});
});
</script>
</head>
<body>
<input type="button" value="輸出class類"/>
<input type="button" value="設(shè)置class類"/>
<input type="button" value="追加class類"/>
<input type="button" value="刪除全部class類"/>
<input type="button" value="刪除指定class類"/>
<input type="button" value="重復(fù)切換class類"/>
<input type="button" value="判斷元素是否含有某個(gè)class類"/>
<p class="myClass" title="選擇你最喜歡的水果." >你最喜歡的水果是?</p>
<ul>
<li title='蘋果'>蘋果</li>
<li title='橘子'>橘子</li>
<li title='菠蘿'>菠蘿</li>
</ul>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.test{
font-weight:bold;
color : red;
}
.add{
font-style:italic;
}
</style>
<script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//獲取<p>元素的color
$("input:eq(0)").click(function(){
alert( $("p").css("color") );
});
//設(shè)置<p>元素的color
$("input:eq(1)").click(function(){
$("p").css("color","red")
});
//設(shè)置<p>元素的fontSize和backgroundColor
$("input:eq(2)").click(function(){
$("p").css({"fontSize":"30px" ,"backgroundColor":"#888888"})
});
//獲取<p>元素的高度
$("input:eq(3)").click(function(){
alert( $("p").height() );
});
//獲取<p>元素的寬度
$("input:eq(4)").click(function(){
alert( $("p").width() );
});
//獲取<p>元素的高度
$("input:eq(5)").click(function(){
$("p").height("100px");
});
//獲取<p>元素的寬度
$("input:eq(6)").click(function(){
$("p").width("400px");
});
//獲取<p>元素的的左邊距和上邊距
$("input:eq(7)").click(function(){
var offset = $("p").offset();
var left = offset.left;
var top = offset.top;
alert("left:"+left+";top:"+top);
});
});
</script>
</head>
<body>
<input type="button" value="獲取<p>元素的color"/>
<input type="button" value="設(shè)置<p>元素的color"/>
<input type="button" value="設(shè)置<p>元素的fontSize和backgroundColor"/>
<input type="button" value="獲取<p>元素的高度"/>
<input type="button" value="獲取<p>元素的寬度"/>
<input type="button" value="設(shè)置<p>元素的高度"/>
<input type="button" value="設(shè)置<p>元素的寬度"/>
<input type="button" value="獲取<p>元素的的左邊距和上邊距"/>
<p title="選擇你最喜歡的水果."><strong>你最喜歡的水果是?</strong></p>
<ul>
<li title='蘋果'>蘋果</li>
<li title='橘子'>橘子</li>
<li title='菠蘿'>菠蘿</li>
</ul>
</body>
</html>