css.html
<!DOCTYPE html>
<html>
<head>
<title>js控制html标签的属性和内容</title>
<style type="text/css">
#box01{width: 100px;height: 100px;background:pink;}
</style>
</head>
<body>
<div id="box01" title="我是title属性" class="class01">我是一个div盒子</div>
</body>
</html>
js.html
<!DOCTYPE html>
<html>
<head>
<title>js控制html标签的属性和内容</title>
<style type="text/css">
#box01{width: 100px;height: 100px;background:pink;}
</style>
</head>
<body>
<div id="box01" title="我是title属性" class="class01">我是一个div盒子</div>
</body>
</html>
<script type="text/javascript">
//1.先获得指定的id属性
var box01 = document.getElementById('box01');
//2.改变div中的title属性
box01.title = '我是被js改变的title';
//2.改变class的属性
box01.className = 'class02';
//3.改变div显示的内容
box01.innerHTML = '我是被js修改的html属性'
</script>
上述代码各自粘贴进入txt文本后,然后重命名如上,双击打开即可见效。
其中script type的意思是下面的代码是什么语法