如何将数据从输入字段写入进度标记

how to write data from an input field to a progress tag

本文关键字:字段 数据 输入      更新时间:2023-09-26

我遇到了一个问题,我通常非常擅长js(但有时事情往往会从我的脑海中消失)这不是我最好的时间之一,我第一次使用html5进度元素,阅读w3文档,但它们并没有真正的帮助,我会给你我的代码,你能告诉我出了什么问题吗?

<!DOCTYPE html>
<html>
<body>
<progress id="myProgress" value="75" max="100">
</progress>
<hr>
<input type ="text" id="myTextarea"></input>
<button onclick="myFunction()">write to progress</button>
<hr>
<script>
function myFunction() {
    var x = document.getElementById("myTextarea").value;
    document.getElementById("myProgress").innerHTML = x;
}
</script>
</body>
</html>

只需使用进度条的value属性。

<!DOCTYPE html>
<html>
<body>
<progress id="myProgress" value="75" max="100">
</progress>
<hr>
<input type ="text" id="myTextarea"></input>
<button onclick="myFunction()">write to progress</button>
<hr>
<script>
function myFunction() {
    var x = document.getElementById("myTextarea").value;
    document.getElementById("myProgress").value = x;
}
</script>
</body>
</html>