html 编写网页 输入用户名密码 点确定对了 转接到另一页面,不对提示错误

html 编写网页 输入用户名密码 点确定对了 转接到另一页面,不对提示错误,第1张

<script type="text/javascript">

function cpmlhx(){

var c=document.getElementById('ljmtea').value

var p=document.getElementById('taobao').value

if (c=='123' &&p=='123'){

alert("回答正确\n\n加十分!")

return true

}

else {

alert("用 户 名 或 密 码 错\n\n请 重 新 输 入 \n\n谢 谢!")

return false

}

}

</script>

<form onsubmit='return cpmlhx()' method='post' action='ok.htm'>

用户名:<input type='text' id='ljmtea' name='ljmtea'>

密码:<input type='password' id='taobao' name='taobao'>

<input type='submit' value='登录'>

</form>

用户名,密码:123

试试是不是这种效果

请注意getElementByld与getElementById的区别, 在百度知道页面上看好像没有区别, 建议把编辑器的字体改成Courier字体,这样小写的L与大写的i的区别就明显了

你定义的check()函数没有返回值, 应当返回布尔值. 当检测不通过时返回false可阻止表单提交.

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>表单实验</title>

    <script>

        function check(form) {

            var p1 = form.passwd1

            var p2 = form.passwd2

            if (p1.value != p2.value) {

                p2.oninvalid()

                return false

            }

            return true

        }

        onload = function() {

            var p2 = document.forms["my_f1"].passwd2

            p2.oninvalid = function() {

                this.setCustomValidity("密码不一致,请重新输入")

            }

            p2.oninput = function() {

                this.setCustomValidity("")

            }

        }

    </script>

</head>

<body>

    <form action="" method="post" name="my_f1" onsubmit="return check(this)">

        <p>密码:

            <input type="password" required="true" name="passwd1" />

        </p>

        <p>密码确认:

            <input type="password" required="true" name="passwd2" />

        </p>

        <p>

            <input type="submit" value="提交" />

        </p>

    </form>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7678492.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存