求助!表单验证_html/css_WEB-ITnose
但是,
如果先输入重复密码,再输入密码,然后离开焦点的时候 即使2次不一致,也显示的2个都是正确。这是因为输入密码后离开焦点的时候只是验证了自己而没有匹配和下面重复密码的值 ,这个问题怎么解决?
我的思路是 既然重复密码离开焦点的时候验证匹配上面密码的值,那么也让先输入重复密码,再输入密码,然后离开焦点的时候,眼验证下面的重复密码的值。 但如何做到呢???????下面是代码
function checktag(p){
var x=p.nextSibling;
while(x.nodeName!="SPAN")
{
x=x.nextSibling
}
return x;
} //获取INPUT后面的SPAN一个方法
//此函数用于传值,有三个参数,第三个是一个函数的指针,它不被执行函数体,所以为FUN
function yanzhenghanshu(i,ppp,fun,tishi,k) {
i.onfocus= function gaoliang() //获取焦点时,触发的方法
{
if(i.value=="") {checktag(i).innerHTML=ppp; checktag(i).className="d"}
else if(fun()){checktag(i).innerHTML=ppp; checktag(i).className="d"}
else {checktag(i).innerHTML="请重新输入";checktag(i).className="a"}
}
i.onblur= function likai() //失去焦点时触发的方法
{
if(fun()){checktag(i).innerHTML="输入正确";checktag(i).className="c"}
else if (i.value==""){checktag(i).innerHTML=ppp;checktag(i).className="a"}
else {checktag(i).innerHTML=tishi;checktag(i).className="b"}
}
if(k=="hi") {
if(fun()){checktag(i).innerHTML="输入正确";checktag(i).className="c"}
else if (i.value==""){checktag(i).innerHTML=ppp;checktag(i).className="b"}
else {checktag(i).innerHTML=tishi;checktag(i).className="b"}
}
}
onload=yanzhengaaa;
function yanzhengaaa(k){
var stutas=true;
var qu=document.getElementsByTagName("input")[0];
var bo=document.getElementsByTagName("input")[1];
var o=document.getElementsByTagName("input")[2];
var b=document.getElementsByTagName("input")[3]; //获取INPUT对象
//以下是:通过一个函数 为每个INPUT的获取和失去焦点时候的状态 传三个值,第三个传的是函数,这个函数叫回调函数
yanzhenghanshu(qu,"请输入用户名称",function()
{
var zhengze=/^[a-z]\w/; var ha=/\s/g;
if(zhengze.test(qu.value)==true && qu.value.length>=6 && qu.value.length {return true}
else
{ stutas=false; return false}
}
,"输入错误",k);
yanzhenghanshu(bo,"请输入密码" ,function()
{
var zheng=/\w/; var ha=/\s/g;
if(zheng.test(bo.value)==true&&bo.value.length>=6&&bo.value.length {return true}
else
{stutas=false;return false}
}
,"输入错误",k);
yanzhenghanshu(o,"请再次输入密码",function()
{
var zheng=/\w/; var ha=/\s/g;
if(zheng.test(o.value)==true&&o.value.length>=6&&o.value.length {return true}
else
{ stutas=false;return false}
}
,"输入错误或两次密码不一致",k);
yanzhenghanshu(b,"请输入邮箱地址",function()
{
var zhengze=/^[a-z]\w/; var ha=/\s/g;
if(zhengze.test(b.value)==true&&b.value.length>=6&&qu.value.length {return true}
else
{stutas=false;return false}
}
,"输入错误",k);
return stutas;
}
回复讨论(解决方案)
你可以参考一下这个,很有用而且可以扩展的一个JS文件
http://download.csdn.net/detail/sgyyz/4358592
你应该在表单的onsubmit()事件中验证

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.
