失去焦点时检查并验证输入字段 [英] Check and Validate input field when loses focus

查看:60
本文介绍了失去焦点时检查并验证输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用onblur和onfoucus,但我不知道应用java脚本代码。

< input name =emailaddresstype =textvalue =Fill

onFocus =clearText(this)önBlur=clearText(this)>



我想要相同的功能,即使用此链接网站下面

链接到这里.....请点击查看

解决方案

试试这个.. :)



 <   div  >  
电子邮件:
< 输入 type = text name = email id = txtEmail onblur = validateForm() >
< label id = lblError style < span class =code-keyword> =
color:red > < span class =code-keyword>< / label >
< / div >





Javascript

  function  validateForm(){
var x = document .getElementById( txtEmail)。value;
var atpos = x.indexOf( @);
var dotpos = x.lastIndexOf( );
if (atpos< 1 || dotpos< atpos + 2 || dotpos + 2 > = x.length){


< span class =code-sdkkeyword> document
.getElementById( lblError)。 innerHTML = 输入有效的电子邮件地址;
}
else {
document .getElementById( lblError)。innerHTML = ;
}
}





您也可以调用相同的函数onfocus .. :))


I am using onblur and onfoucus but i am do't know apply java script code.
<input name="emailaddress" type="text" value="Fill"
onFocus="clearText(this)" önBlur="clearText(this)">

I want to same functionality ,which is using this link site below
link here.....please click and check

解决方案

try this.. :)

<div>
      Email:
      <input type="text" name="email" id="txtEmail" onblur="validateForm()">
      <label id="lblError" style="color:red"></label>
  </div>



Javascript

function validateForm() {
         var x = document.getElementById("txtEmail").value;
         var atpos = x.indexOf("@");
         var dotpos = x.lastIndexOf(".");
         if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {


             document.getElementById("lblError").innerHTML = "Enter valid email Address";
         }
         else {
             document.getElementById("lblError").innerHTML = "";
         }
     }



You can call same function onfocus also.. :)


这篇关于失去焦点时检查并验证输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆