我創建了一個從列表中隨機打開網站的簡單腳本。我最近嘗試添加一項功能,使用戶可以選擇每頁打開和關閉之間的等待時間(以毫秒爲單位)。這裏是我的代碼:爲什麼這段文字沒有更新?
<!DOCTYPE html>
<html>
<head>
<title>Smokescreen</title>
</head>
<body align="center" style="font-family:monospace">
<h2 align="center" style="font-family:monospace">
SmokeScreen
</h2>
<h3 align="center" style="font-family:monospace">
SmokeScreen is a JavaScript program that opens a random site every 3 seconds,
</h3>
<h3 align="center" style="font-family:monospace">
to create a "smokescreen" over your browser history, preventing anyone from [easily] finding your information.
</h3>
<h4 align="center" style="font-family:monospace">To exit, close the original window that has the text "Smokescreen" in the title.</h4>
<p align="center" style="font-family:monospace">
<a href="github.com/keeganjk/smokescreen" style="font-family:monospace" align="center">Source Code/Learn More</a>
<br />
<div style="width: 300px; border: 25px solid #800000; margin:0 auto; font-family:monospace;" align="center">
<h4 align="center" style="font-family:monospace">Milliseconds to wait before closing page:</h4>
<h4 id="one" align="center" style="font-family:monospace"></h4>
<button onclick="millisecs = prompt('New time to wait (in milliseconds)?'); if (isNaN(milliseconds)) {millisecs = millisecsBackup} else {millisecsBackup = millisecs} document.getElementById('one').innerHTML = millisecs;" style="font-family:monospace" align="center">Set Wait Time</button>
<br />
<br />
</div>
<br />
<div style="margin:0 auto; font-family:monospace" align="center">
<button onclick="getRandom(0, list.length, millisecs);" style="font-family:monospace" align="center">Start!</button>
</div>
</p>
<script src="script.js"></script>
<script>
var millisecs = 3000;
var millisecsBackup = 3000;
document.getElementById("one").innerHTML = millisecs;
</script>
</body>
</html>
出於某種原因,在h4
文本與one
的id
,當我在不同的號碼中鍵入沒有更新。我做錯了什麼?
提取從您的按鈕時獲取用戶輸入到函數的代碼。然後當按鈕被點擊時執行該功能。這將允許您調試您的功能。 – Ken
您應該學會從HTML中分離出style *(CSS)*和functional *(JavaScript)*,並使用外部腳本。 – PHPglue