您的位置:首页 > Web前端 > JavaScript

JS实现表单验证

2011-12-17 02:47 513 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

<!--

body,td,th {

    font-size: 12px;

    color: #000000;

}

body {

    background-color: #CCCCCC;

    margin-left: 0px;

    margin-top: 0px;

}

a {

    font-size: 12px;

    color: #666600;

}

a:link {

    text-decoration: none;

}

a:visited {

    text-decoration: none;

    color: #000099;

}

a:hover {

    text-decoration: underline;

    color: #6633FF;

}

a:active {

    text-decoration: none;

    color: #00FF00;

}

-->

</style>

    <script type="text/javascript">

        function checkusername()

        {

            var myform = document.getElementByIdx_x_x("form1");

            var username = myform.username.value.length;

            if(username < 1||username>12)

            {

                errusername.innerHTML = "<font color='red'>用户名不符合要求</font>";

                return false;

            }else{

                errusername.innerHTML = "<font color='green'>用户名符合要求</font>";

                return true;

            }

        }

        function checkage()

        {

            var myform = document.getElementByIdx_x_x("form1");

            var age = myform.age.value;

            if(age != parseInt(age))

            {

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息