2015-11-02 66 views
0

我需要幫助我的功能。我有我所有的變數。 需要幫助切換頁面

var swith = document.getElementById("sub"); 
 
var one = document.getElementById("rule"); 
 
var two = document.getElementById("cool"); 
 
var three = document.getElementById("fool"); 
 

 
Function cool() { 
 
\t if(swith,one) window.location.replace("app.html"); 
 
};
<html> 
 
<head> 
 
<title>question?</title> 
 
<link href="app.css" rel="stylesheet" type="text/css"/> 
 
</head> 
 
<body id="QA"> \t 
 
<select id="much"> 
 
<option id="rule">0-10,000</option> 
 
<option id="cool">25,00-50,000</option> 
 
<option id="fool">75,000-100,000</option> 
 
<input type="submit" id="sub"> 
 
<script src="app.js"></script> 
 
</select> 
 
</body> 
 
</html>

我想我錯過了一些重要的東西。但谷歌表示「未捕獲的SyntaxError:意外的標識符」。

+1

JavaScript是大小寫敏感的。 '函數'不'函數' – j08691

+1

app.js中有什麼? – santon

回答

1

嘗試小寫fFunction如:

function cool() { 
    if(swith,one) window.location.replace("app.html"); 
}; 
0

功能的大寫字母 「F」 是在javascript中function constructor。 您應該使用常規函數表達式。

我建議添加一個value屬性,並在提交包含表單時執行提交的邏輯,而不是將id屬性添加到選項。

我附上了一個原始代碼段,您可以根據需要進行擴展和修改。由於表單提交的沙盒,此片段提交不適用於此網站。

window.onload = function() { 
 

 
    document.getElementById("TestForm").addEventListener("submit",function(e) { 
 
    
 
     if (this.value === "rule") { 
 
     document.location.replace('app.html'); 
 
     } 
 
    },false); 
 
    
 
    
 
};
<html> 
 

 
<head> 
 
    <title>question?</title> 
 
</head> 
 

 
<body id="QA"> 
 
    <form id="TestForm" name="TestForm" action="#"> 
 
    <select id="much"> 
 
    <option value="rule">0-10,000</option> 
 
    <option value="cool">25,00-50,000</option> 
 
    <option value="fool">75,000-100,000</option> 
 
    </select> 
 
    <input type=submit value="Submit"/> 
 
    </form> 
 
</body> 
 

 
</html>