JS如何获取文本框的数字而响应另一个文本框相应的进度条?

过程如下:1.在第一个文本框输入一个百分比2,第二个文本框里的进度条随着第一个文本框输入的数值而开始响应。直到结束为止。谢谢大神的帮助。

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .progress {
            width: 500px;
            height: 40px;
            border: 1px solid #eeeeee;
            overflow: hidden;
            margin: 20% auto;
        }
        input {
            width: 150px;
        }
        .progress span{
            height: 40px;
            background-color: red;
            display: block;
            width: 0;
            line-height: 40px;
            text-align: right;
        }
    </style>
</head>
<body>
<input type="number" min="0" max="100" id="input">
<div class="progress">
    <span></span>
</div>
<script>
    ~function (document) {
        var input = document.getElementById('input');
        var progress = document.getElementsByClassName('progress')[0];
        var span = progress.getElementsByTagName('span')[0];

        input.addEventListener('input', function () {
            span.style.width = span.textContent =  this.value + '%';
        }, false)
    }(document)
</script>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-04-20
利用onchange事件处理追问

我要的是代码啊!
大神

追答

你的html代码与css代码不贴出来,怎么给你写js代码?