<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript">
spreadSheet= new Array(9),summary="";
for(var i=0; i<spreadSheet.length; i++)
spreadSheet[i]=0;
document.writeln("<h1>Poll<\/h1><form method='get' id='tally' action=''>");
document.writeln("<p>Enter Sales Amount:<br/><input type='text' id='cash'/><input type='button' value='calculate' onclick='calculateSalary()'/><\/p>");
document.writeln("<\/form>");
function calculateSalary(){
var value=document.getElementById("cash").value;
switch(value){
case (value<300):++spreadSheet[0]; break;
case (value<400):++spreadSheet[1]; break;
case (value<500):++spreadSheet[2]; break;
case (value<600):++spreadSheet[3]; break;
case (value<700):++spreadSheet[4]; break;
case (value<800):++spreadSheet[5]; break;
case (value<900):++spreadSheet[6]; break;
case (value<1000):++spreadSheet[7];break;
default:++spreadSheet[8];break;
}
}
function display(){
summary="Number of People who earned salaries in the following ranges: \n\n";
summary+="$200 – 299:\t" + spreadSheet[0] + "\n";
summary+="$300 – 399:\t" + spreadSheet[1] + "\n";
summary+="$400 – 499:\t" + spreadSheet[2] + "\n";
summary+="$500 – 599:\t" + spreadSheet[3] + "\n";
summary+="$600 – 699:\t" + spreadSheet[4] + "\n";
summary+="$700 – 799:\t" + spreadSheet[5] + "\n";
summary+="$800 – 899:\t" + spreadSheet[6] + "\n";
summary+="$900 – 999:\t" + spreadSheet[7] + "\n";
summary+="$1000 and over\t" + spreadSheet[8] + "\n";
return summary;
}
document.writeln("<textarea cols='80' rows='15'>"+display()+"<\/textarea>");
</script>
</head>
<body>
</body>
</html>
我是一個JavaScript新手,是的,我真的試過,然後再發布幫助自己。爲什麼這個腳本不工作? [JS]
我只想做一個簡單的程序,在用戶輸入需要從一個按鈕,然後遞增基於關值的用戶輸入的一個全局數組元素。問題是我無法讓全局數組正常工作。我究竟做錯了什麼?
日誌中沒有錯誤消息? – 2013-03-02 08:33:33
爲什麼在'
'部分使用'document.write()'?它應該在''中。 – jfriend00 2013-03-02 08:35:43請澄清「不工作」 – 2013-03-02 08:36:47