通用Java验证脚本 [英] Common Javascript for Validation

查看:89
本文介绍了通用Java验证脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将comman JavaScript文件用于四个验证目的.
例子

I am using comman JavaScript file for four validation purpose.
Example

//.js file code
function chkBlank(id)
{
    if(id.value == "")
    {
        alert("Please enter the value");
       id.focus();
        return false;
    }
}


.aspx file 
<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="UI_Login_Login" %>]]>


<script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        txtuserid.Attributes.Add("onblur", "check(document.getElementById('txtuserid'));")
    End Sub
</script>



我遇到错误,需要对象.我可以知道我要去哪里了吗?
我是ASP.NET的新手.

在此先感谢



I am getting error, object required. May i know where am I going wrong?
I am new to ASP.NET.

Thanks in advance

推荐答案

将属性行更改为

Change attribute line as

txtuserid.Attributes.Add("onblur", "check(this);")


dhage.prashant01写道:
dhage.prashant01 wrote:

txtuserid.Attributes.Add("onblur","check(document.getElementById(''txtuserid''));)

txtuserid.Attributes.Add("onblur", "check(document.getElementById(''txtuserid''));")



这是您做错的地方.

您期望文本框的对象,根据您提示警报的值.

而是使用"this".它将传递完整的文本框对象,您可以使用与使用document.getElementById
选择它时相同的方式使用它
因此更改将是:



This is where you are doing wrong.

you are expecting an object of textbox, based on which value you prompt an alert.

Instead use ''this''. it will pass the full textbox object and you can use it the same way as if its selected using document.getElementById

Thus the change would be:

txtuserid.Attributes.Add("onblur", "check(this);")


感谢伙计们

我已经做了类似的事情

.js文件
thanks guys

I have done something like that

.js file
function chkBlank(objId, lblText)
{
    if(objId.value == "")
    {
        alert("Please enter " + lblText);
        objId.focus();
        return false; 
    }
    else
    {
        return true;
    }
}



.aspx文件



.aspx file

<script type="text/javascript" src="../JS/Validation.js"></script>
    <script type="text/javascript" language="javascript">







function Validate()
{
        if(chkBlank(document.getElementById('txtuserid'),document.getElementById('lblUserId').innerText) == false){return false;}
        if(chkBlank(document.getElementById('txtpwd'),document.getElementById('lblPwd').innerText) == false){return false;}
}



.aspx.vb



.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtuserid.Focus()
        imgblogin.Attributes.Add("onclick", "javascript:return Validate();")
End Sub


这篇关于通用Java验证脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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