• 试题:用JavaScript实现密码验证功能


    问题描述:

    1) 当用户在密码框中输入密码且密码框失去焦点时,验证密码的正确性。

    如输入密码等于"123456",提示用户密码验证正确。否则,提示用户密码验证错误,并使密码框作为焦点。

    2) 当用户点击重置按钮时,清空所有文本输入框。

    <html>

        <head>

        <title>用户登录 </title>

    <script language="Javascript">

    function verifyPwd(pw){

     

    }

     

    function resetValue(){

     

    }

     

    </script>

        </head>

    <body bgcolor="#EEEEEE"><font color="blue">

        <form name="loginForm">

        用户名:

        <input type="text" name="user" size="30">

        <br>  密码:

        <input type="password" name="pwdField" size="30"  

    onblur="return verifyPwd(this)" >

        <br>

        <input type=button value="确定" >

            <input type=button value="重置

    onclick="return resetValue()” >   

           </form>

    </body>

    </html>

     

    复习知识点:

    1、对于获得表单元素的引用方法有很多种,有通过getElementById()方法,只需传入表单的ID就可以得到相应的表单的引用,我们还用documentfrom集合。如下的两种形式都可以得到相应表单的引用:

         Var myform = document.forms[i]//i为相应表单的索引;

     Var myfrom = document.forms[“formname”]//formname为相应的表单名。

    答案:

    function verifyPwd(pw){

     

     

    if(pw.value=="123456")

    {

    alert("密码输入正确");

    }else{

    alert("密码输入错误");

    }

    }

     

    function resetValue(){

    document.forms["loginForm"].reset();//这里是调用表单中的reset()方法,这个方法相当于<input type="reset" value="重置"/>

     

    }

  • 相关阅读:
    小量程称重传感器
    一个苹果证书怎么多次使用——导出p12文件
    ios申请真机调试( xcode 5)详细解析
    iOS Developer:真机测试
    mac使用技巧
    How to Create a Provisioning Profile for iPhone
    ios申请真机调试( xcode 5)详细解析
    ui develop
    google ip address
    remove xcode recent projects from dock menu 移除xcode dock菜单显示的项目列表
  • 原文地址:https://www.cnblogs.com/liangjingguo/p/3345128.html
Copyright © 2020-2023  润新知