HTML DOM

1. prompt()

Refer to https://www.w3school.com.cn/jsref/met_win_prompt.asp

<html>
    <head>
    <script type="text/javascript">
        function display(){
            var name = prompt("Please enter your name",'origin')
            if(name != null && name != "") {
                document.write("hello " + name)
            }
        } 
    </script>
    </head>
    <body>
        <input type="button" onclick="display()" value="Display box">
    </body>
</html>

 2. classList

Refer to https://www.runoob.com/jsref/prop-element-classlist.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<style>
.mystyle {
     300px;
    height: 50px;
    background-color: coral;
    color: white;
    font-size: 25px;
}
</style>
</head>
<body>

<p>点击按钮为 DIV 元素添加 "mystyle" 类。</p>
<button onclick="myFunction()">点我</button>
<p><strong>注意:</strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 classList 属性。</p>
<div id="myDIV">
我是一个 DIV 元素。
</div>
<script>
function myFunction() {
    document.getElementById("myDIV").classList.add("mystyle");
}
</script>

</body>
</html>
原文地址:https://www.cnblogs.com/chenqr/p/11324781.html