美文网首页
JS 中常见事件

JS 中常见事件

作者: 醉叶惜秋 | 来源:发表于2018-08-13 09:48 被阅读14次

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

相关文章

网友评论

      本文标题:JS 中常见事件

      本文链接:https://www.haomeiwen.com/subject/ctxkbftx.html