Javascript Object 设计测试例子!

JS文件:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
/***************************
       obj Tools
***************************
*/
var g_EListObjects;

function eAddListObj(listId, jsonDESCityList)
{
    
if (typeof(g_EListObjects) == "undefined")
        g_EListObjects
=new Array();
            
    g_EListObjects[listId]
=jsonDESCityList;
}

function eGetListObj(listId)
{
    
return g_EListObjects[listId];
}

function setBackIcon(obj,tipType)
{
    
if(obj != null)
    {
        
if(tipType == "no")
        {
            obj.className 
= "formline_nomsg";
        }
        
else if(tipType == "error")
        {
            obj.className 
= "formline_errmsg";
        }
        
else if(tipType == "right")
        {
            obj.className 
= "formline_ritmsg";
        }
        
else
        {
            obj.className 
= "formline_msg";
        }
    }
}
    
/***************************
     WebHolderPicker
***************************
*/
function WebHolderPicker() 
{
    
//public property
    this.webHolderPickerId;
    
this.webHolderInputId;
    
this.webHolderPickerTipId;
    
this.webHolders;
    
this.pageLanguage;
    
this.webStrHolderInputInfo;
    
//private property
    var strHoldersOptions;
    
    
//init method
    this.InitHolderList = function(strHolders)     
    {
        
if(strHolders != null && strHolders != "")
        {
            
this.webHolders = strHolders.split(',');
        }
    } 
    
    
this.SetHolderPickerTip = function(strTip,tipType)    
    {
        
var obj = document.getElementById(this.webHolderPickerTipId);
        
if(obj != null)
        {
            obj.innerHTML 
= strTip;
            setBackIcon(obj,tipType);
        }
    }
    
    
this.SetSelectValue = function(strOptions)     
    {
        
var obj = document.getElementById(this.webHolderPickerId);
        
if(obj != null)
        {
            obj.innerHTML 
= strOptions;
        }
    }
    
    
//public method
    this.CheckHolderName = function()    
    {
        
var obj = document.getElementById(this.webHolderInputId);
        
var value = "";
        
if(obj != null)
        {
            value 
= obj.value.toLowerCase();
        }

        ISCHECKMOBILEOK 
= false;
        
var checkResult = true;

        
if(value == null || value == "")
        {
            checkResult 
= false;
            
this.SetHolderPickerTip(this.webStrHolderInputInfo,"info");
            
if(HAVECLICKSUBMIT)
            {
                
this.SetHolderPickerTip(submitCardHolderError,"error");
            }
            
return;
        }
        
else (value.length > 0
        {
            
var patrn=/^[0-9]{8,16}$/;
            
if (!patrn.exec(value))
            {
                checkResult 
= false;
            }
        }        
        
        
if(checkResult)
        {
            
this.SetHolderPickerTip(this.strHolderRight,"right");
            ISCHECKMOBILEOK 
= true;
        }
        
else
        {
            
this.SetHolderPickerTip(this.strHolderError,"error");
        }
    }
    
    
this.SetHolder = function(strHolder)    
    {
        
var obj = document.getElementById(this.webHolderInputId);
        
if(obj != null)
        {
            obj.value 
= strHolder;
            
this.CheckHolderName();
        }
    }
    
    
//display List
    this.ShowHolderList = function()     
    {
        
var webHolderSet = this.webHolders;
        
if(this.pageLanguage == "en")
        {
            
this.strHoldersOptions = '<input type="text" οnblur="eGetListObj(\'' + this.webHolderPickerId + '\').CheckHolderName();" οnchange="eGetListObj(\'' + this.webHolderPickerId + '\').CheckHolderName();" maxlength="11" name="mobile" value="" id="mobile" />';
        }
        
else
        {
            
this.strHoldersOptions = '<input type="text" οnblur="eGetListObj(\'' + this.webHolderPickerId + '\').CheckHolderName();" οnchange="eGetListObj(\'' + this.webHolderPickerId + '\').CheckHolderName();" maxlength="11" name="mobile" value="" id="mobile" />';
        }            

        
this.SetSelectValue(this.strHoldersOptions);
        
this.SetHolderPickerTip(this.webStrHolderInputInfo,"info");
    }      
}

 

Default.aspx文件:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jsObject._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>Untitled Page</title>
    
<script language="javascript" type="text/javascript" src="js/jsObject.js"></script>
    
<link href="../css/template.css" type="text/css" rel="stylesheet"/>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<div id="inputWebHolderPicker"></div>
        
<div id="inputWebHolderPicker_Tip"></div>
        
<br />
        
<input type="button" value="Test" />
    
</div>
    
</form>
    
<script type="text/javascript" language="javascript">
        
var HAVECLICKSUBMIT = false;
        
var ISCHECKMOBILEOK = false;
        
        
var inputWebHolderPicker = new WebHolderPicker();
        inputWebHolderPicker.webHolderPickerId 
= "inputWebHolderPicker";
        inputWebHolderPicker.webHolderInputId 
= "mobile";
        inputWebHolderPicker.webHolderPickerTipId 
= "inputWebHolderPicker_Tip";
        
//inputWebHolderPicker.webHolders = "";
        inputWebHolderPicker.pageLanguage = "cn";
        inputWebHolderPicker.webStrHolderInputInfo 
= "请输入移动电话";
        inputWebHolderPicker.strHolderRight 
= "OK";
        inputWebHolderPicker.strHolderError 
= "Error";
    
        eAddListObj(inputWebHolderPicker.webHolderPickerId,inputWebHolderPicker);    
        
//eGetListObj(inputWebHolderPicker.webHolderPickerId).InitHolderList(dataStrCardHolders);
        eGetListObj(inputWebHolderPicker.webHolderPickerId).ShowHolderList();
    
</script>
</body>
</html>

 

CSS文件:

 

ContractedBlock.gif ExpandedBlockStart.gif Code

.formline_msg 
{ background-image: url(../images/info.gif); background-repeat:no-repeat; width:265px!important;width:275px; padding-left:18px; margin-top:3px;list-style-position:inside; float:left; color:#666; }
.formline_nomsg 
{ width:265px; padding-left:18px; margin-top:3px;list-style-position:inside; float:left; }
.formline_errmsg 
{ background-image: url(../images/error.gif); background-repeat:no-repeat; width:265px!important;width:275px; padding-left:18px; margin-top:3px;list-style-position:inside; float:left; color:red;}
.formline_ritmsg 
{ background-image: url(../images/right.gif); background-repeat:no-repeat; width:265px!important;width:275px; padding-left:18px; margin-top:3px;list-style-position:inside; float:left;}

 

转载于:https://www.cnblogs.com/adam/archive/2008/08/09/1264380.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值