方式一: 方式二: 方式三: ...
方式一:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
window.onload=function(){
var p=document.getElementById("id1")
alert(p.nodeName)
}
</script>
</head>
<body>
<p id="id1">hello p</p>
</body>
</html>
方式二:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-3.3.1.min.js"></script>
<script>
$(document).ready(function(){
$("p").css("color","red")
})
</script>
</head>
<body>
<p>hello world</p>
</body>
</html>
方式三:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-3.3.1.min.js"></script>
<script>
$(function(){
$("p").css("color","red")
})
</script>
</head>
<body>
<p>hello world</p>
</body>
</html>