2017-04-21 82 views
0

我創建了一個從列表中隨機打開網站的簡單腳本。我最近嘗試添加一項功能,使用戶可以選擇每頁打開和關閉之間的等待時間(以毫秒爲單位)。這裏是我的代碼:爲什麼這段文字沒有更新?

<!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文本與oneid,當我在不同的號碼中鍵入沒有更新。我做錯了什麼?

+0

提取從您的按鈕時獲取用戶輸入到函數的代碼。然後當按鈕被點擊時執行該功能。這將允許您調試您的功能。 – Ken

+0

您應該學會從HTML中分離出style *(CSS)*和functional *(JavaScript)*,並使用外部腳本。 – PHPglue

回答

0

您正在檢查if (isNaN(milliseconds)),但您將其稱爲變量millisecs,以便引發錯誤。

如果您使用的是現代瀏覽器,請嘗試打開開發人員工具(Windows上的Windows/CMD + OPT + i上的F12)並檢查控制檯。

也請考慮您的移動內嵌樣式/ onclicks到<style><script>標籤:)

+0

我曾考慮過這樣做,但這對某些瀏覽器不兼容; GitHub上的一些人告訴我要擴展兼容性,所以我猜我是「蠻力」我的兼容方式......;) – keeganjk