验证不是't工作,现在我的网站也坏了
Validation isn't working and now my site is broke as well
我在"插入数字,输出答案"方面做得很好。但我需要在网站上进行验证,这样只有某些东西才能起作用。我的网站在进行验证时,完全停止了工作,我不完全理解为什么或发生了什么。
JS小提琴:http://jsfiddle.net/ufs869wu/
HTML:
<form id="form1" name="form1" method="post" action="">
<label for="txtAge">Age:</label>
<input type="text" class="txtInput" id="txtAge" value="0"/><p id="ageRes"></p>
<br/>
<label for="txtMass">Mass in Lbs:</label>
<input type="text" class="txtInput" id="txtMass" value="0"/>
<br/>
<label for="txtHinch">Height in Inches:</label>
<input type="text" class="txtInput" id="txtHinch" value="0"/>
<br/>
<input type="button" id="btnCalc" value="Calculate"/>
<p id="result2">Result</p>
</form>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="BMI.js"></script>
</body>
和JS
// JavaScript Document
$(function () {
//Identify Variables
var txtMass, txtHinch, result;
var isValid = $('#form1').validate().form();
// attach event listener to the toggle button's click event
$('#btnCalc').click(function () {
//Set validator
$.validator.setDefaults({
errorElement: "span",
errorClass: "form_error",
errorPlacement: function(error,element){
error.insertAfter(element)
}
});
$.extend($.validator.messages,{
required: "* Required field"
});
//Set Validation perameters
$("#form1").validate({
rules: {
txtAge: {
required: true,
range: [1, 120],
digits: true
},
txtMass: {
require: true,
digits: true
},
txtHinch: {
requre: true,
digits: true
}
}
});
if (isValid) {
//Set Age range for form accuracy
if (txtAge < 16 || txtAage > 80){
//Output
$('#ageRes').html('Results may not be accurate at your age')
} else { (txtAge >= 16 || txtAge <= 80)
$('#ageRes').html('Results should be accurate considering your age')
//Equation for BMI
result = ($('#txtMass').val() / ($('#txtHinch').val() * $('#txtHinch').val())) * 703;}
//If - Else statement from output of BMI equation
if (result < 16){
$('#result2').html('Result: '+result.toFixed(1) + ' you are Severely underweight')
} else if (result <=18 ){
$('#result2').html('Result: '+result.toFixed(1) + ' you are underweight')
} else if (result <=24){
$('#result2').html('Result: '+result.toFixed(1) + ' you are healthy')
} else if (result <= 30 ){
$('#result2').html('Result: '+result.toFixed(1) + ' you are seriously overweight')
} else if (result <=35 ){
$('#result2').html('Result: '+result.toFixed(1) + ' you are obese')
} else if (result <=40 ){
$('#result2').html('Result: '+result.toFixed(1) + ' you are seriously obese')
}
}
});
});
感谢您的帮助!
您在加载jquery之前调用了'$',并得到一个'$'是未定义的错误。尝试将这一行向上移动到html的头部。
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
此外,您是否在某个地方包含了jquery验证插件?。我不认为它包括在任何地方。
相关文章:
- 如何识别我的网站中的慢速设备
- 将电视直播频道从网站嵌入我的网站
- 在我的网站上显示最近提交的文章/图片
- 使用API在我的网站Google-Map上显示搜索地址的纬度和经度
- 如果我的内容/网站有名字,我可以用不同的方式设计我的网站吗
- 错误编码的Adsense广告正在扼杀我的网站's的性能
- 创建类似Facebook的按钮是'窃听'为我的网站
- 在我的网站上使用DogeScript
- 在我的网站上以纯文本形式添加最新推文
- 如何在jsoup的帮助下跟踪我的网站是否加载到android设备上
- 如何在我的网站上嵌入yammer私人信息
- 如何让iPhone用户在我的网站上观看带字幕的视频
- 如何在不影响网站页面速度的情况下在我的网站上使用谷歌字体
- 如何使用XMLHttpRequest()不断地将数据发送到我的网站中的另一个页面
- 在我的网站上创建一个在1-10之间不断变化的数字时遇到了问题.Javascript
- jquery ias插件不适用于我的网站,加载更多项目不起作用
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- 在一天中的某个时间自动在我的网站上播放视频
- 跨浏览器问题:如何调试我的网站'在windows PC的safari上的行为
- 我可以让我的网站的内容可编辑区域对安卓股票浏览器上的触摸事件更敏感吗