以下是要用到的js代碼,一般單獨放一個js檔案,本例放置到myjs.js檔案當中,以下是引用該檔案的代碼; <script language="javascript" src="myjs.js" type="text/javascript"></script>代碼如下:
var icon = '<img src="image/warning.gif" width="14" height="14" border="0" align="top">';
var ns = ["Loginname","Password","Passw","Mail","Companyname","Tel","Fax","Dizhi","Zip","Linkname","Shouji","Url","Jieshao","Yanzheng"];
// 換一張圖片
function SetImage(){
//
var rod = Math.round(Math.random() * 100);
$('ImaYanZhen').src = "image/loading.gif";//
$('ImaYanZhen').src = "ValidateCode.aspx?id=" + rod;
}
function checkUsr(s){
var ma = ["使用者名稱(4-16位)!","使用者名稱由數字、英文、底線、中杠線組成!"];
if(!limitLen(s,4,16)){
showInfo("Loginname",ma[0]);
return false;
}
if(!hasAccountChar(s)){
showInfo("Loginname",ma[1]);
return false;
}
showInfo("Loginname");
return true;
}
function isLoginname(s)
{
var ma = ["使用者名稱(4-16位)!","使用者名稱由數字、英文、底線、中杠線組成!","此使用者名稱已被註冊,請另換一個。","請等待,資料載入中..."];
var icons = '<img src="image/loading.gif" width="14" height="14" border="0" align="top">';
if(!limitLen(s,4,16)){
showInfo("Loginname",ma[0]);
return false;
}
if(!hasAccountChar(s)){
showInfo("Loginname",ma[1]);
return false;
}
$("TisiLoginname").className = "focus";
$("LoginnameInfo").innerHTML = icons + ma[3];
var bRet = join.GetReturnCode(s).value;
if(bRet == "1"){
$("TisiLoginname").className = "error";
$("LoginnameInfo").innerHTML = icon + ma[2];
}
else
{
showInfo("Loginname");
}
}
function checkPwd(s){
var ma = ["密碼(6-20位)!","密碼不能包含中文或全形符號!","兩次輸入的密碼不一致!"];
if(!limitLen(s,6,16)){
showInfo("Password",ma[0]);
return false;
}
if(hasChineseChar(s)){
showInfo("Password",ma[1]);
return false;
}
showInfo("Password");
return true;
}
function checkPwd2(s){
var ma = ["密碼(6-20位)!","密碼不能包含中文或全形符號!","兩次輸入的密碼不一致!"];
if(!limitLen(s,6,16)){
showInfo("Passw",ma[0]);
return false;
}
if(hasChineseChar(s)){
showInfo("Passw",ma[1]);
return false;
}
if( s==trim($("TexPassword").value))
{
showInfo("Passw");
return true;
}
else{
showInfo("Passw",ma[2]);
return false;
}
}
function checkEml(s){
var ma = ["請輸入常用郵件!","郵件格式不正確!"];
if(s.length < 5){
showInfo("Mail",ma[0]);
return false;
}
if(!isEmail(s)){
showInfo("Mail",ma[1]);
return false;
}
showInfo("Mail");
return true;
}
function checkCompany(s){
var ma = ["企業名稱不可為空!"];
if(!limitLen(s,1,100)){
showInfo("Companyname",ma[0]);
return false;
}
showInfo("Companyname");
return true;
}
function checkPhone(){
var ma = ["電話國家代碼不可為空!","電話區號不可為空!","電話號碼不正確!"];
var gj = $("TexTelGJ").value;
var qh = $("TexTelQH").value;
var s = $("TexTel").value;
if(gj.length == 0){
showInfo("Tel",ma[0]);
return false;
}
if(qh.length == 0){
showInfo("Tel",ma[1]);
return false;
}
if(!isPhone(gj + "-" + qh+"-" + s)){
showInfo("Tel",ma[2]);
return false;
}
showInfo("Tel");
return true;
}
function checkFax(){
var ma = ["傳真國家代碼不可為空!","傳真區號不可為空!","傳真號碼不正確!"];
var gj = $("TexFaxGJ").value;
var qh = $("TexFaxQH").value;
var s = $("TexFax").value;
if(gj.length == 0 && qh.length == 0 && s.length == 0)
{
$("TisiFax").className = "lond";
$("FaxInfo").innerHTML = "";
return true;
}
if(gj.length == 0){
showInfo("Fax",ma[0]);
return false;
}
if(qh.length == 0){
showInfo("Fax",ma[1]);
return false;
}
if(!isPhone(gj + "-" + qh + "-" + s)){
showInfo("Fax",ma[2]);
return false;
}
showInfo("Fax");
return true;
}
function checkDizi(s){
var ma = ["企業地址不可為空!"];
if(!limitLen(s,1,100)){
showInfo("Dizhi",ma[0]);
return false;
}
showInfo("Dizhi");
return true;
}
function checkZip(s){
var ma = ["郵遞區號格式不正確!"];
if(s.length == 0){
$("TisiZip").className = "lond";
$("ZipInfo").innerHTML = "中國地區使用者請填寫規範的6位郵遞區號。";
return true;
}
if(!isZip(s)){
showInfo("Zip",ma[0]);
return false;
}
showInfo("Zip");
return true;
}
function checkShengfen(){
var ma = ["請選擇公司所在省份!","請選擇公司所在市區!"];
var sh,qu;
sh = $("DropShengfen").selectedIndex;
qu = $("DropDiqu").selectedValue;
if(sh == 0){
showInfo("Shengfen",ma[0]);
return false;
}
if(qu == ""){
showInfo("Shengfen",ma[1]);
return false;
}
showInfo("Shengfen");
return true;
}
function checkLinkname(s){
var ma = ["連絡人不可為空!"];
if(!limitLen(s,2,20)){
showInfo("Linkname",ma[0]);
return false;
}
showInfo("Linkname");
return true;
}
function checkShouji(s){
var ma = ["手機格式不正確!"];
if(s.length == 0){
$("TisiShouji").className = "lond";
$("ShoujiInfo").innerHTML = "建議您填寫,以便潛在客戶及時與您取得聯絡!";
return true;
}
if(!isMobile(s)){
showInfo("Shouji",ma[0]);
return false;
}
showInfo("Shouji");
return true;
}
function checkUrl(s){
var ma = ["網址格式不正確!"];
if(s == "HTTP://" || s.length == 0){
$("TisiUrl").className = "lond";
$("UrlInfo").innerHTML = "請在網址前加:HTTP://。";
return true;
}
if(!isURL(s)){
showInfo("Url",ma[0]);
return false;
}
showInfo("Url");
return true;
}
function checkJieshao(s){
var ma = ["企業介紹不可為空!"];
if(!limitLen(s,1,2000)){
showInfo("Jieshao",ma[0]);
return false;
}
showInfo("Jieshao");
return true;
}
function checkYanzheng(s){
var ma = ["驗證碼不可為空!","驗證碼為4位字母或數字!","驗證碼輸入錯誤,請重新輸入!"];
if(s.length == 0)
{
showInfo("Yanzheng",ma[0]);
return false;
}
if(s.length < 4)
{
showInfo("Yanzheng",ma[1]);
return false;
}else{
var ses = join.sessions().value;
if(s.toLowerCase() != ses)
{
showInfo("Yanzheng",ma[2]);
return false;
}
}
showInfo("Yanzheng");
return true;
}
function inputfocus(n,i)
{
var ma = ["4-16位;只限數字(0-9)和英文(a-z),不區分大小寫;建議使用公司名稱簡稱。",
"6-20位,區分大小寫, 不能與使用者名稱相同;建議為英文字母(a-z)和數字(0-9)結合,便於記憶,不易被猜出。",
"請再輸入一遍上面填寫的密碼。",
"請填寫常用的電子郵箱,這是客戶聯絡您的一種方式!",
"請使用中文填寫貴公司的全稱。",
"很重要!這是客戶聯絡您的主要方式!",
"請填寫完整的公司地址。",
"中國地區使用者請填寫規範的6位郵遞區號。",
"請選擇公司所在省市。",
"請填寫連絡人的真實姓名。",
"建議您填寫,以便潛在客戶及時與您取得聯絡!",
"請在網址前加:HTTP://。",
"可以填入最多2000字的企業介紹。",
"請輸入左側顯示的驗證字串(不區分大小寫)。"];
var fdo = $("Tisi" + n);
var ido = $(n + "Info");
fdo.className = "focus";
ido.innerHTML = ma[i];
}
function showInfo(n,s){
var fdo = $("Tisi" + n);
var ido = $(n + "Info");
if(typeof s == 'undefined'){
fdo.className = "ok";
ido.innerHTML = "填寫正確!";
}else{
fdo.className = "error";
ido.innerHTML = icon + s;
}
}
function submits(){
checkUsr($("Tex" + ns[0]).value);
checkPwd($("Tex" + ns[1]).value);
checkPwd2($("Tex" + ns[2]).value);
checkEml($("Tex" + ns[3]).value);
checkCompany($("Tex" + ns[4]).value);
checkPhone();
checkFax();
checkDizi($("Tex" + ns[7]).value);
checkZip($("Tex" + ns[8]).value);
checkShengfen();
checkLinkname($("Tex" + ns[9]).value);
checkShouji($("Tex" + ns[10]).value);
checkUrl($("Tex" + ns[11]).value);
checkJieshao($("Tex" + ns[12]).value);
checkYanzheng($("Tex" + ns[13]).value);
for(var i=0;i<ns.length;i++){
if( $("Tisi" + ns[i]).className == "error"){
$("Tex" + ns[i]).focus();
return false;
}
else{
continue;
}
}
// return true;
var fax = "", fw = "", mes = "由於網路原因註冊失敗,請聯絡管理員。";
var baomi = 0;
var tel = $("TexTelGJ").value + "-" + $("TexTelQH").value +"-"+$("TexTel").value;
if(trim($("TexFax").value) != ""){
fax = $("TexFaxGJ").value + "-" + $("TexFaxQH").value +"-"+$("TexFax").value;
}
for(var i =1;i<7;i++){
if($("CheckBox" + i).Checked == "Checked"){
fw += $("CheckBox" + i).value + ",";
}
}
if($("RadioButtonList1_0").checked == "checked"){
baomi = 0;
}
else{
baomi = 1;
}
var a1 = $("TexLoginname").value;
var a2 = $("TexPassword").value;
var a3 = $("TexMail").value;
var a4 = $("TexCompanyname").value;
var a5 = $("TexDizhi").value;
var a6 = $("TexZip").value;
var a7 = $("DropShengfen").value;
var a8 = $("DropDiqu").value;
var a9 = $("TexLinkname").value;
var a10 = $("TexShouji").value;
var a11 = $("TexUrl").value;
var a12 = $("DropDownList3").value;
var a13 = $("TexJieshao").value;
var bRet = join.AddCompanya(a1,a2,a3,a4,tel, fax,a5,a6,a7,a8,a9,a10,baomi,a11,a12, fw,a13,$('HidIP').value).value;
if(bRet == "1"){
location.href="Default.aspx";
}
else{
alert(bRet);
}
// 調用背景代碼 寫入資料庫
}
function initPage(){
for(var i=0;i<ns.length;i++){
$("Tex" + ns[i]).value = "";
}
}
說明: 以下是代碼的應用,請參考: <asp:TextBox ID="TexPassword" runat="server" BorderStyle="Groove" MaxLength="16" onfocus="inputfocus('Password',1)" onkeyup="checkPwd(this.value);" onblur="checkPwd(this.value);"
TextMode="Password" Width="150px"></asp:TextBox>
<asp:TextBox ID="TexPassw" runat="server" BorderStyle="Groove" MaxLength="16" onfocus="inputfocus('Passw',2)" onkeyup="checkPwd2(this.value);" onblur="checkPwd2(this.value);" Width="150px" TextMode="Password"></asp:TextBox>.........................................................