在 JavaScript 中成功验证后,我无法显示任何消息
I am unable to show any message after successful validation In JavaScript
在 JavaScript 中成功验证后,我无法显示任何消息,如果语句最终我会出错。我想显示我们会在通过验证后回复您。
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x.length < 10) {
window.alert("The field cannot contain more than 10 characters!");
return false;
}
}
function validateForm() {
var k = document.forms["myForm"]["query"].value;
if (k.length < 25) {
window.alert("The field cannot contain atleast 25 characters!");
return false;
}
}
function validateForm() {
var k1 = document.forms["myForm"]["email"].value;
var atpos = k1.indexOf("@");
var dotpos = k1.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= k1.length) {
alert("Not a valid e-mail address");
return false;
}
if (k1.length < 10) {
window.alert("The field cannot contain atleast 25 characters!");
}
}
if (x && k && k1 !== true) {
this.x = x;
this.k = k;
this.k1 = k1;
window.alert("We will get back to you");
}
</script>
function validateForm() {
var isValid = true;
var x = document.forms["myForm"]["fname"].value;
if (x.length < 10){
window.alert("The field cannot contain more than 10 characters!");
isValid = false;
}
var k = document.forms["myForm"]["query"].value;
if (k.length<25) {
window.alert("The field cannot contain atleast 25 characters!");
isValid = false;
}
var k1= document.forms["myForm"]["email"].value;
var atpos = k1.indexOf("@");
var dotpos = k1.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= k1.length) {
alert("Not a valid e-mail address");
isValid = false;
}
if (k1.length < 10) {
window.alert("The field cannot contain atleast 25 characters!");
isValid = false;
}
if (!isValid) {
// you should take a look here.. what do you want to achieve?
this.x = x;
this.k = k;
this.k1 = k1;
window.alert("We will get back to you");
}
return isValid;
}
表单应使用 onsubmit
属性:
<form onsubmit="return validateForm()"></form>
看看 http://jqueryvalidation.org/documentation/.你可以考虑开始学习jQuery或其他js框架。
相关文章:
- D3.js生成有效的SVG,但不显示任何内容
- HTML 5 和 3.js 代码不会在网页上显示任何内容
- jquery Ajax没有;不要显示任何信息(既不显示成功也不显示失败)
- javascript函数,该函数不起作用,但不会显示任何错误
- JavaScript 未显示任何警报对话框
- 谷歌地图没有显示任何标记
- 没有使用Highcharts显示任何图形
- jQuery导航下拉菜单未显示..任何想法
- AngularJS:console.log不显示任何内容
- ng-repeat不显示任何内容
- ng-重复不显示任何内容
- extjs在chrome中可以正常工作;不要在firefox或ie中显示任何内容
- 使用javascript在标签上不显示任何内容
- console.log在FF插件生成器中没有显示任何内容
- TypeAhead.js没有显示任何输出Rails
- 使用ajax运行php脚本不会显示任何结果
- 我的Javascript项目正在访问网络摄像头,但没有显示任何内容
- 日期-时间范围指令字段未显示任何值
- owl.carousel help-没有显示任何东西
- PhoneGap-Javascript没有显示任何响应