JS 中常见事件

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

效果图


image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容