我有一个我创建的进度条,现在我只是将进度值附加到<h1>
标记。我想实现的是用新的价值取代旧的价值。我不确定是否有可用于更新值或类似内容的保留字。任何帮助或推动正确的方向将不胜感激。更改文本字符串的值
谢谢!
这是我到目前为止有:
const button = document.getElementById("btn");
const bar = document.getElementById("progress-bar");
const heading = document.getElementById("visual-progress");
button.addEventListener('click', function(){
if(bar.value >= 100) {
bar.value=100;
} else {
bar.value+=25;
}
document.getElementById("visual-progress").append(bar.value);
});
body {
max-width: 1200px;
margin: 0 auto;
padding: 10px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-top: 3em;
}
progress {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 100%;
height: 20px;
-webkit-transition: all 5s;
transition: all 5s;
}
progress::-webkit-progress-bar {
background-color: #ccc;
width: 100%;
}
progress::-webkit-progress-value {
background-color: orange !important;
}
button {
margin-top: 2em;
background: black;
color: white;
border: none;
padding: .5em 2em;
}
button:hover {
background: #1a1a1a;
}
.hide {
display: none;
}
<body>
<h2 id='visual-progress'>Quiz Progress</h2>
<progress id='progress-bar' max='100' value='0'></progress>
<button id='btn'>Next</button>
</body>
有没有涉及到他的问题的一些原因,使得你建议更换“视觉进步”文本(和使用额外的变量,似乎没有理由),而不是取代“进度栏”文本? –
他肯定希望改变“视觉进步”文本。这就是我理解这些要求的方式,看起来我是对的。这也跟他的片段一样... – dhilt