<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>使用jQuery操作DOM之操作样式</title>
<style type="text/css" >
.red
{
color:red;}
.bold
{
font-weight:bold;}
.italic
{
font-style:italic;}
.hidden
{
visibility:hidden;
}
</style>
<script type="text/javascript" src="jquery-2.1.0.js"></script>
<script>
$(document).ready(function()
{
$("button").eq(0).click(function()
{
$("p").addClass("red");
})
$("button").eq(1).click(function()
{
$("p").addClass("bold");
})
$("button").eq(2).click(function()
{
$("p").addClass("italic");
})
$("button").eq(3).click(function()
{
$("p").removeClass("red");
})
$("button").eq(4).click(function()
{
$("p").removeClass("bold");
})
$("button").eq(5).click(function()
{
$("p").removeClass("italic");
})
$("button").eq(6).click(function()
{
$("p").toggleClass("hidden");//移出与追加的重复过程。
})
});
</script>
</head>
<body>
<p>段落文本<img src="images/android.jpg"></p>
<button>红色</button>
<button>加粗</button>
<button>斜体</button>
<button>去掉红色</button>
<button>去掉加粗</button>
<button>去掉斜体</button>
<button>隐藏</button>
</body>
</html>
41、实例 使用jQuery操作DOM之操作样式
最新推荐文章于 2023-09-02 15:36:04 发布