其他分享
首页 > 其他分享> > 蒲式耳,磅换算成公斤和吨

蒲式耳,磅换算成公斤和吨

作者:互联网

一个小东西,给自己留作备份用的

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>蒲式耳, 磅 换算成公斤和吨</title>

    <style>
        #box1{ margin-bottom: 50px; }
        .des{ font-size: 13px; color: #666; margin: 10px 0;}

    </style>
</head>
<body>
    <div id="box1">
        <input type="text" placeholder="请输入蒲式耳" id="txt">
        <button id="btn">蒲式耳转化为千克和吨</button>
        <div class="des">
            1蒲式耳 = 27.216公斤
        </div>
        <div id="content"></div>
    </div>

    <div>
        <input type="text" placeholder="请输入磅" id="txt2">
        <button id="btn2">磅转化为千克和吨</button>
        <div class="des">
            1磅 = 0.45359237公斤
        </div>
        <div id="content2"></div>
    </div>
    <script>
        window.onload = function () {
            let btn = document.getElementById('btn')
            let txt = document.getElementById('txt')
            let content = document.getElementById('content')

            btn.onclick = function() {
                let num = txt.value * 27.216
                content.innerHTML = txt.value + '蒲式耳' + ' = ' + num + '公斤' + ' = ' + num * 2 + '斤' + ' = ' + num / 1000 + '吨'
            }

            let btn2 = document.getElementById('btn2')
            let txt2 = document.getElementById('txt2')
            let content2 = document.getElementById('content2')

            btn2.onclick = function() {
                let num = txt2.value * 0.45359237
                content2.innerHTML = txt2.value + '磅' + ' = ' + num + '公斤' + ' = ' + num * 2 + '斤' + ' = ' + num / 1000 + '吨'
            }
        }
    </script>
</body>
</html>

 

标签:公斤,document,num,value,getElementById,换算,let,txt,蒲式耳
来源: https://www.cnblogs.com/carol1987/p/15146145.html