我一直在努力做這個代碼,但我似乎無法讓它像我想要的那樣工作。我想提出一個提示,詢問你在一個主題上工作了多長時間,然後在進度條上給出正確的寬度。調試一個XP吧
編輯:widthGenerator創建彈出窗口,但我似乎無法在widthGenerator()中將可變寬度轉換爲Move()作爲Move的寬度。
這裏是我的代碼:
<body class="w3-container">
<div class="w3-progress-container w3-round-xlarge">
<div id="myBar" class="w3-progressbar w3-round-xlarge" style="width:1%"></div>
</div>
<button class="w3-btn" onclick="move()">Click Me</button>
<script>
function widthGenerator() {
var question = prompt("Enter number of hours worked:", "Enter here");
if (isNaN(question) == false) {
var width = (question * 2.33463);
break;
} else if (isNaN(question) == true) {
question = prompt("That is not a number; Enter the number of hours worked:", "Enter here");
break;
};
}
function move() {
var elem = document.getElementById("myBar");
var id = setInterval(frame, 1);
var width = widthGenerator()
function frame() {
if (width >= widthGenerator()) {
clearInterval(id);
} else {
width += 0.1;
elem.style.width = width + '%';
}
}
}
</script>
它以什麼方式不起作用?你有錯誤嗎?包括你的帖子中出現了什麼問題。 – dckuehn
修正它以描述問題是什麼。 – Ian