我对javascript很新,所以很难看出我哪里出错了。出于某种原因,我的功能无法正常工作。任何帮助,将不胜感激。我尝试在外部js文件中使用它们,头部/身体似乎没有任何效果。错误是使用函数或调用它们。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Nicky's</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
function CheckfName() {
var name=0;
var checknames=isNaN(name);
window.alert("Please use only letters in the name space");
return false; }
function checkc number() {
var cellN=0;
var numBercheck=isNan(cellN);
window.alert("Please use only numbers in the cell number space");
return false }
function confirmBooking() {
if(document.forms[0].firstName.value==0
|| document.forms[0].lastName.value.value==0) {
window.alert("Please fill in your First and Last name");
return false; }
if(document.forms[0].firstName.value==""
|| document.forms[0].lastName.value=="") {
window.alert("Please fill in your first and last name");
return false; }
else if(document.forms[0].areaCode.value==""
|| document.forms[0].threeMiddlenumbers.value==""
|| document.forms[0].LastfourNumbers.value=="") {
window.alert("Please enter your cell number.");
return false; }
else if(document.forms[0].hairstyles.value=="Setdefault"
|| document.forms[0]servCes.value=="Setdefault") {
window.alert("Please select hairstyle type");
return false; }
else if(document.forms[0].day.value=="SelectDay"
|| document.forms[0].month.value=="SelectMonth"
|| document.forms[0].time.value=="Selectime") {
window.alert("Please select the Day, Month and Time!");
return false; }}
function resetBooking() {
var reset=window.confirm("Are you sure that you want to reset
your booking information?");
if(reset==true) {
return true;
return false; }}
</script>
</head>
<body>
<div class="wrapper">
<div id="header">
</div>
<ul id="navlist">
<li><a href="Home.html">Home</a></li>
<li><a href="BookingOrOrder.html">Booking</a></li>
<li><a href="Services.html">Services</a></li>
<li><a href="ContactUs.html">Contact Us</a></li>
</ul>
<div id="article">
<form method="get" action="BookingProcessor.html" enctype="application/x-www-form-urlencoded"
onsubmit="return confirmBooking();" onreset="return resetBooking();">
<p>First Name
<input type="text" onchange="CheckfName()" name="firstName" maxlength="35" size="35"
style="margin-left:20px;"/>
</p>
<p>Last Name
<input type="text" onchange="CheckfName()" name="lastName" maxlength="35" size="35"
style="margin-left:28px;"/>
</p>
<p>Cell Number
<input type="text" onchange="CheckCnumber()" name="areaCode" size="3" maxlength="3"
style="margin-left:15px;">
<input type="text" name="threeMiddleNumbers" size="3" onchange="CheckCnumber()"
maxlength="3"/>
<input type="text" name="LastfourNumbers" size="4" onchange="CheckCnumber()"
maxlength="4"/>
<p>Hairstyle Type
<select name="hairstyles">
<option value="Setdefault">Select Hairstyle</option>
<option value="none">None</option>
<option value="straightBack">Straight back long</option>
<option value="Bondings">Bondings</option>
<option value="hairByhair">Hair by hair</option>
<option value="blowNcut">Blow and Cut</option>
<option value="bopCorn">Bopcorn</option>
<option value="twistLong">Twist Long</option>
<option value="dreadS">Dreads</option>
</select
</p>
<select name="day">
<option value="SelectDay">Select Day</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="month">
<option value="SelectMonth">Select Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="time">
<option value="Selecttime">Select Booking Time</option>
<option value="8to9">Between 8am and 9am</option>
<option value="9to10">Between 9am and 10am</option>
<option value="10to11">Between 10am and 11am</option>
<option value="11to12">Between 11am and 12pm</option>
<option value="12to13">Between 12pm and 13pm</option>
<option value="13to14">Between 13pm and 14pm</option>
<option value="14to15">Between 14pm and 15pm</option>
<option value="15to16">Between 15pm and 16pm</option>
<option value="16to17">Between 16pm and 17pm</option>
<option value="17to18">Between 17pm and 18pm</option>
</select>
<p>If there are any other requirements, please specify in the text area below</p>
<p>
<textarea name="Requirement" cols="40" rows="3" style="overflow: hidden;">
</textarea>
</p>
<p>
<input type="submit" value="Place a Book">
<input type="reset" value="Reset a Form">
</form>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
以下是我发现的一些问题。
function checkNumber() {
var cellN=0;
var numBercheck=isNan(cellN);
window.alert("Please use only numbers in the cell number space");
return false;
}
使用checkNumber
代替&#34; checkc编号&#34;,在返回语句后也没有分号
function resetBooking() {
var reset=window.confirm("Are you sure that you want to reset your booking information?");
if(reset==true) {
return true;
}
return false;
}
如果陈述错误(它有2次退货)
答案 1 :(得分:0)
您的功能名称中有拼写错误。应该没有空间。
function checkc number() {
var cellN=0;
var numBercheck=isNan(cellN);
window.alert("Please use only numbers in the cell number space");
return false }
将名称更改为功能 checkcnumber()。 你还在return语句中缺少分号。