本文目錄一覽:
- 1、JS表單註冊驗證
- 2、js表單驗證代碼怎麼寫
- 3、JS表單驗證代碼
- 4、asp表單提交註冊驗證js問題
- 5、js註冊表單驗證代碼
- 6、用html做的一個form+table註冊頁面里有一個驗證碼,要怎麼寫這個js代碼??
JS表單註冊驗證
把以下代碼加到body里試一試 本應寫成function 就是做個示意給你看看原理
昵稱:
input type=”text” onclick=”this.style.border=’1px #cd1b1b solid’;document.getElementById(‘a’).innerHTML=”;” onblur=”this.style.border=’1px #000000 solid’;if(this.value==”){document.getElementById(‘a’).innerHTML=’昵稱不能為空!’;}”/span id=”a”/spanbr /br /
密碼:
input type=”text” onclick=”this.style.border=’1px #cd1b1b solid’;document.getElementById(‘b’).innerHTML=”;” onblur=”this.style.border=’1px #000000 solid’;if(this.value==”){document.getElementById(‘b’).innerHTML=’密碼不能為空!’;}”/span id=”b”/span
js表單驗證代碼怎麼寫
我來舉個例子,很簡單的
!DOCTYPE html
html
head
meta charset=”UTF-8″
titleInsert title here/title
script type=”text/javascript”
function formCheck(){//表單驗證
var userForm=document.forms.userForm;
if(userForm.username.value==null||userForm.username.value.length=0){
alert(“用戶名不能為空”);
return false;
}else if(userForm.username.value.length6||userForm.username.value.length20){
alert(“用戶名必須為6-20位”);
return false;
}else if(userForm.password.value==null||userForm.password.value.length=0){
alert(“密碼不能為空”);
return false;;
}else if(userForm.password.value.length6||userForm.password.value.length20){
alert(“密碼必須為6-20位”);
return false;
}else{
userForm.submit();
}
}
/script
/head
body
form action=”” name=”userForm”
userName:input type=”text” name=”username”br
password:input type=”password” name=”password”br
input type=”button” value=”提交” onclick=” formCheck()”
/form
/body
/html
JS表單驗證代碼
我就簡單的寫個 希望可以幫助您
==================================
!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”
html xmlns=””
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ /
title測試頁面/title
script type=”text/javascript”
function checkform(){
//驗證用戶名
if($(“username”).value == “”){
$(“n_msg”).innerHTML =”用戶名不可以為空”;
$(“username”).select();
$(“username”).focus();
return false;
}else{
if($(“username”).value.length 6){
$(“n_msg”).innerHTML = “用戶名必須大於6個字符”;
$(“username”).select();
$(“username”).focus();
return false;
}
}
//驗證密碼
if($(“password”).value == “”){
$(“p_msg”).innerHTML =”密碼不可以為空”;
$(“password”).select();
$(“password”).focus();
return false;
}else{
if($(“password”).value.length 10){
$(“p_msg”).innerHTML = “密碼必須大於10個字符”;
$(“password”).select();
$(“password”).focus();
return false;
}
}
//…..(下面的可以以此類推)
return true;
}
function $(id){
return document.getElementById(id);
}
/script
style type=”text/css”
body{ font:12px 宋體}
.c_red{ color:#f00}
/style
/head
body
table width=”500″ border=”0″ cellspacing=”0″ cellpadding=”0″
form method=”post” onsubmit=”return checkform()”
tr
td width=”89″用戶名/td
td width=”223″input name=”username” type=”text” id=”username” //td
td width=”188″ id=”n_msg” class=”c_red”/td
/tr
tr
td密碼/td
tdinput name=”password” type=”password” id=”password” //td
td id=”p_msg” class=”c_red”/td
/tr
tr
td colspan=”3″input name=”sub” type=”submit” id=”sub” value=”提交” //td
/tr
/form
/table
/body
/html
===========================
上面的為代碼部分 我已經調試沒問題 希望可以幫助您
祝早日解決~
asp表單提交註冊驗證js問題
if (document.form1.radio2.checked document.form1.img.value==””)
{
alert(“圖片不能為空”);
return false;
}
name=img 的那個input框最好加個id=img
否則取不到值的話就用document.getElementByName(”)
js註冊表單驗證代碼
JS函數:
function check(){
var username = document.getElementById(“username”).value;
var pass1 = document.getElementById(“password”).value;
var pass2 = document.getElementById(“confirm_password”).value;
if (username == “”|| username == NULL || pass1 == “” || pass1 == NULL || pass2 == NULL || pass2 == “”) {
alert(“用戶名或密碼不得為空!”);
return false;
}
}
表單提交的時候驗證:
input name=”reg” type=”submit” value=”提交” onclick=”return check()”/
自己補全。
用html做的一個form+table註冊頁面里有一個驗證碼,要怎麼寫這個js代碼??
可以用JS做個簡單的驗證碼 script language=”javascript”var code; //在全局 定義驗證碼
function createCode()
{ //創建驗證碼函數
code = “”;
var codeLength =5;//驗證碼的長度
var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,’A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’,’L’,’M’,’N’,’O’,’P’,’Q’,’R’,’S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’);//所有候選組成驗證碼的字符,當然也可以用中文的
for(var i=0;icodeLength;i++)
{
var charIndex =Math.floor(Math.random()*36);
code +=selectChar[charIndex];
}// 設置驗證碼的顯示樣式,並顯示
document.getElementById(“discode”).style.fontFamily=”Fixedsys”; //設置字體
document.getElementById(“discode”).style.letterSpacing=”3px”; //字體間距
document.getElementById(“discode”).style.color=”#ff0000″; //字體顏色
document.getElementById(“discode”).innerHTML=code; // 顯示
}/script 把上面一段JS代碼放到head/head標籤中在頁面裝載的時候,調用驗證碼創建函數 body onload=”createCode()
“在驗證碼輸入框的後面放一個標籤 span id=”discode”/span
原創文章,作者:KSIPI,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/317882.html