Html-Js语法

Html-Js语法

920 发布: 2023/1/12 13:16 本文总阅读量
一个简单的hmtl
<!DOCTYPE html>
<html lang=zh-CN>
    <head>
        <meta charset=utf-8>
        <meta http-equiv=X-UA-Compatible content="IE=edge">
        <title>三体盒子</title>
        <style>
            .logo-box {
                display: flex;
                justify-content: center;
                margin-top:60%;
            }
        </style>
    </head>
    <body>
        <div class="logo-box">
            <img src="./index_def.jpg" alt="" />
        </div>
    </body>
</html>
快速跳转到某个位置
<div class="control" id="inputForm">
    <input class="input" type="text" id="name" placeholder="请输入您的姓名">
</div>
......
<a href="#inputForm" style="color:#ffff">返回输入框位置</a>

点击事件

书写方式1

#html
<div>
    <span class="agree" id="agree">同意</span>
</div>

#js
$("#agree").click(function(){
    console.log('点击了')
    ...
});

书写方式2

#html
<div>
    <span class="agree" id="agree">同意</span>
</div>

#js
document.getElementById("agree").onclick = function() {
    console.log('点击了')
};

书写方式3

#html
<div>
    <span class="agree" id="agree" onclick="clickAgree()">同意</span>
</div>

#js
clickAgree = function(){
    console.log('点击了')
}

字符串01转布尔值
let str = '0'
let bool = !! + str