我自己记录的JavaScript笔记

一    .客户端验证用户输入的是否是数字.
<script language=javascript>
<!--
/*客户端验证用户输入的是否是数字.
也可以用 正则表达式,     var p =  /\d{1,2}/ ; if ( "hello123".test(p) == true ) { alert ( 'OK' ) ;} */
function t(txt)
{
    var p =  /\d{1,2}/ ;
         var v = txt.value ;
         var len = 0 ;
         var hasDot = false;
         //去头.
          for (i=0;i<txt.value.length;i++)
        {
            if( v.charCodeAt(i) <48 || v.charCodeAt(i) >57 )        //如果不是数字.
            {
                 v = v.substr(1,v.length - 2 ) ;
             }
             else
             {
                 break;
             }
         }
            
         //去尾
         start = v.length;
          for (i=0;i<start;i++)
        {
            if( v.charCodeAt(i) > 47 && v.charCodeAt(i) <58 )        //如果是数字.
            {
                 len ++ ;
             }
             else
             {
                if ( hasDot && v.charCodeAt(i) == 46) break;
                if ( v.charCodeAt(i) == 46 )
                {
                    hasDot = true ;
                    len ++;
                    continue;
                }
                 break;
             }
         }
        txt.value= v.substr(0,len);
}
//-->
</script>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 56px; POSITION: absolute; TOP: 88px" runat="server" onkeyup = "t(this);" ></asp:TextBox>

二    .检查输入是否为汉字
function chinaonly()
    {
        if(document.form1.country.value == "中国")
        {
        form1.signname.value=form1.signname.value.replace(/[^\u4E00-\u9FA5]/g,'');
        }
    }
三    .服务器端如何得到客户端信息.如何解析客户端的Hidden内容? <input type="hidden" name="__VIEWSTATE" value="" />

 
六.操作 Select 的例子. sss为Select的ID
for(var i = window.document.all.sss.options.length ;i>0 ; i--)
{
     window.document.all.sss.options[i] = null;
}
 window.document.all.sss.add( new Option("abc","abc"));
 window.document.all.sss.add( new Option("abc1","abc1"));
 window.document.all.sss.add( new Option("ab21","ab21"));    //var str = window.document.all.name.value;
七.    定时刷新页面.<script>
function rl(){
document.location.reload()
}
setTimeout(rl,10000)
</script>

另一种
<head>
<meta http-equiv="refresh" content="5;url=http://www.logoshow.net">
</head>

八.如何指定页面加载显示的方式 ,一种是生成即显示,一种是加载完成后再显示.
    Response.Buffer
   

    word-wrap: break-word; word-break: break-all
九.CSS 的类表示.
    用两个CSS类的方式 :
            class = "class1 class2"
十.模态对话框.
    在模态对话框中加入 <base target=_self> ,可以在本页提交,关闭,找开连接.
    在找开模态对话框的源窗口用脚本
window.showModalDialog(
"SMD_target.htm",
this,
"dialogHeight: 500px; dialogWidth: 500px; dialogTop: 200px; dialogLeft: 250px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;"
);

posted @ 2009-03-09 00:57  NewSea  阅读(171)  评论(0)    收藏  举报