2014-06-25 59 views
-2
<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
    <script type="text/javascript" src="date_time.js"></script> 
</head> 
<body> 
    <input id="input"><br>What is the number?</input> 
    <button type="button" onclick="getFunction()">Submit</button> 


<script> 
    function getFunction() { 
     var x = document.getElementById('input').value; 
     if (x == 32) { 
      window.alert("Right answer!"); 
     } 
     else { 
      window.alert("Try again."); 
     } 
    } 
</script> 
</body> 
</html> 

所以我想繼續或加載一個新的HTML頁面,當用戶點擊「提交」按鈕,輸入是正確的。有任何想法嗎?也許JS DOM可以幫助...當輸入正確的onload html文件

回答

0

首先你需要添加一個表單標籤,並給它一個名稱,ID和動作。行動應該指向你想要的頁面。

<form name="formname" id="formid" action="mypage.html"> 

您的JavaScript,它是真實的,應該使用簡單:

document.getElementById("formid").submit(); 

它會直接給操作頁面只有當真實。

+0

謝謝,它的工作! – jbuchel