MyFunction.js
function validateForm() {
var frm = document.login;
if(frm.username.value=="abc" && frm.password.value=="abc123"){
alert ();
}else {
alert ();
}
}
MyForm.php
<form id="login" name="login" action="" method="post" onsubmit="return validateForm()" >
<h3>My Login Form</h3>
<p>Username : <input type="text" name="username" id="username" /></p>
<p>Password : <input type="password" name="password" id="password" /></p>
<p><input type="submit" name="submit" id="submit" value="Login" /></p>
</form>
我希望这两个值有效等于abc&amp;&amp; ABC123 我是怎么做到的?
更新的问题 - 2017-01-15
我看着自己的历史,找到了一些我用愚蠢的方式问过的问题。是啊!每个专家都是初学者。没有!我还不是专家。
如何使用jquery验证表单提交?
MyFunction.js
function validateForm() {
var frm = document.login;
if(frm.username.value=="abc" && frm.password.value=="abc123"){
alert ();
}else {
alert ();
}
}
MyForm.php
<form id="login" name="login" action="" method="post" onsubmit="return validateForm()" >
<h3>My Login Form</h3>
<p>Username : <input type="text" name="username" id="username" /></p>
<p>Password : <input type="password" name="password" id="password" /></p>
<p><input type="submit" name="submit" id="submit" value="Login" /></p>
</form>
答案 0 :(得分:0)
这是我正在寻找的代码。我的朋友说,我认为我的问题没有得到澄清。无论如何!我终于写了自己的代码。这是一个简单的表单,如果要查看表单,则必须输入USERNAME作为abc,PASSWORD作为abc123。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>test2</title>
<meta name="description" content="">
<meta name="author" content="ITS The 1 - Yesh">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<script>
function validateForm() {
var frm = document.login;
if(frm.username.value=="abc" && frm.password.value=="abc123"){
alert ("You Are Doing Well");
}else {
alert ("Please Fill Your Username And Password!");
username.focus();
return false;
}
}
</script>
</head>
<body>
<div>
<form id="login" name="login" action="" method="post" onsubmit="return validateForm()" >
<h3>My Login Form</h3>
<p>Username : <input type="text" name="username" id="username" /></p>
<p>Password : <input type="password" name="password" id="password" /></p>
<p><input type="submit" name="submit" id="submit" value="Login" /></p>
</form>
</div>
</body>
</html>
谢谢你们!