Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的异常处理无法捕获?_Javascript_Html - Fatal编程技术网

Javascript 为什么我的异常处理无法捕获?

Javascript 为什么我的异常处理无法捕获?,javascript,html,Javascript,Html,这是我试图为其创建异常处理的html代码。我试图为代码中的第一个表单创建异常 <form id="survey" name="survey" method="post"> <div id="errorText"></div> <fieldset class="labelfloatleft" id="contactinfo"><

这是我试图为其创建异常处理的html代码。我试图为代码中的第一个表单创建异常

<form id="survey" name="survey" method="post">
<div id="errorText"></div>
<fieldset class="labelfloatleft" id="contactinfo"><legend>Your Thoughts</legend>
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" />

<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname"  />

<label for="emailaddress">Email Address</label>
<input type="email" name="emailaddress" id="emailaddress" 
size="30" placeholder="foryou@yahoo.com" />
</fieldset>
<fieldset><legend>Best Movie</legend>

<input type="radio" name="movie" id="horror" value="horror" checked="checked"/>
<label for="horror">The Horror</label>

<input type="radio" name="movie" id="badabing" value="badabing" />
<label for="badabing">Bada-Bing Bada-Boom</label>

<input type="radio" name="movie" id="roll" value="roll" />
<label for="roll">Roll or Die</label>
</fieldset>
<fieldset><legend>Comments</legend>
<label for="message">Your Opinion</label>
<textarea name="message" id="message" rows="7" cols="30"></textarea>
</fieldset>
<input type="submit" value="Send" class="button" id="submitBtn"/>
<input type="reset" value="Cancel" class="button" />
</form>


<h2>Welcome To Our World</h2>

<p class="very">We are a small time movie theater looking to help inspire
people who come to our theater. Our theaters come with
fresh food, cold and hot drinks, souvenirs and comfortable
seats to help make your experience worth while.
</p>

<h2>Most Popular</h2>

<ul>
<li>The Horror</li> 
<li>Bada-Bing Bada-Boom</li> 
<li>Roll or Die</li>
</ul>


<h2>Prices</h2>
<table title="prices">
<tr>
    <th>Ticket</th>
    <th>Price</th>
    <th>Thursday Deal</th>
</tr>
<tr>
    <td>Adult</td>
    <td>$10.00</td>
    <td rowspan="3">Half-Off</td>
    
</tr>
<tr>
    <td>Child</td>
    <td>$6.00</td>
</tr>
<tr>
    <td>Senior</td>
    <td>$8.00</td>
</table>

<form id="price" name="price" method="post">

<fieldset><legend>Ticket Quantity</legend>
<label for="adultinput">Adult 15-60
<input type="text" id="adultinput" value="1" size="2"/>
</label>
<label for="childinput">Child 1-14
<input type="text" id="childinput" value="0" size="2"/>
</label>
<label for="seniorinput">Senior 50 and up
<input type="text" id="seniorinput" value="0" size="2"/>
</label>
</fieldset>

<input type="submit" value="Calculate" id="calculate" class="button" />
<input type="reset" value="Cancel" class="button" />
</form>

看起来您试图访问一个不存在的字段

这里您已经得到了字段的值

var fname = document.getElementById("firstname").value;
var lname = document.getElementById("lastname").value;
var email = document.getElementById("emailaddress").value;
在比较中,您尝试再次访问值字段。但是你已经有了普通的价值

if(!(isNaN(lname.value)) || (lname.value === "")){
}
改为这样做

if(!(isNaN(lname)) || (lname === "")){
}

您好,请缩进您的代码,并提供一个具体的例子,而不是整个项目。我们不需要查看表单的所有字段,一个就足够了。此外,您需要包括您的预期/真实行为,或者是否存在任何错误?
if(!(isNaN(lname)) || (lname === "")){
}