2015-11-02 107 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>