為指定標籤新增新樣式
阿新 • • 發佈:2018-12-26
為特定標籤新增新樣式,這段程式碼實現的是將第三段的內容加上背景色
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
<title>addClass()為標籤新增樣式</title>
<style>
p {
margin: 8px;
font-size: 16px;
}
.cursor{
cursor:pointer;
}
.selected {
color: blue;
}
.highlight {
background: yellow;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
</script>
</head>
<body>
<p>Hello</p>
<p>and</p>
<p>Goodbye</p>
<script>
$( "p" ).addClass( "cursor" );
$( "p" ).last().addClass( "highlight" );
//或者 $( "p:last" ).addClass( "selected highlight" );
</script>
</body>
</html>