html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS 的正删改查</title>
<style>
#main{
background-color: red;
width: 400px;
height: 500px;
}
</style>
</head>
<body>
<div id = 'main'> 我是描述图片的文字</div>
<script src="index.js"></script>
<script>
//alert(0)
</script>
</body>
</html>
JS文件
//JS的增删改查
//增
document.write('hello girl');
//拿到 div
var main = document.getElementById('main');
//1.1创建图像标签
var img = document.createElement('img');
img.src = 'images/IMG_2931.JPG';
img.width = 100;
//1.2添加
main.appendChild(img);
//删
img.remove();
//改
//查
//document.getElementBy...(四种方式)
console.lo
效果图

网友评论