rt,写了一段js脚本,目的是获取用户输入的表单的内容并且通过alert()函数返回以确认信息
先贴html:
<a href="../index.html"><input type='button' value="SUBMIT" name="submit" id="submit" class="apply" onClick="getInfo()" /></a>
然后js脚本:
// JavaScript Document
function getInfo()
{
var username,office,phone,food,amount,cost;
username = document.getElementById("username").value;
office = document.getElementById("office").value;
phone = document.getElementById("phone").value;
food = document.getElementById("food").value;
amount = parseInt(document.getElementById("amount").value);
switch(food){
case "Sizzling Fry Jacks":
cost = 100;break;
case "Earthy Johnny Cake":
cost = 70;break;
case "Cut-o-Brute":
cost = 50;break;
case "Berlize Traditional Beer":
cost = 30;break;
}
cost *= amount;
alert("Username: "+username+"\n"+"Office: "+office+"\n"+"Phone: "+phone+"\n"+"Food: "+food+"\n"+"Amount: "+amount+"\n"+"Total cost: "+cost+"<br /"+"Your food will arrive in 10 minutes!");
}
p.s.:food表单是一个下拉列表,其他都是文本框或者number框
问题出在:js脚本只有正常运行到变量声明部分。再往后面都不能正常运行,alert()函数也不能执行,不能给出提醒,但是也没找到错误。。。
谢谢!
这种问题打断点解决比较好