<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="box">这是文字内容</div>
<script>
// 1.获取元素
const box = document.querySelector('.box')
// 2.修改内容 对象.innerText属性
console.log(box.innerText)
box.innerText = '<strong>这是个盒子</strong>' //不解析标签,strong没啥用
// 3.innerHTML 解析标签
box.innerHTML = '<strong>加粗文字</strong>'
</script>
</body>
</html>
04-DOM修改元素内容
最新推荐文章于 2024-07-12 22:54:26 发布