资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

网页设计动态脚本javascript常用代码大全

来源:常德网站设计 | 2020.12.28

//打开模式对话框
function doselectuser(txtid)
{

      strfeatures=”dialogwidth=500px;dialogheight=360px;center=yes;middle=yes ;help=no;status=no;scroll=no”;
      var url,strreturn;
 
      url=”seluser.aspx”;
       
      strreturn=window.showmodaldialog(url,,strfeatures);  

}

//返回模式对话框的值
function okbtn_onclick()
{
var commstr=;         
     
window.returnvalue=commstr;

      window.close() ;
}
全屏幕打开 ie 窗口
var winwidth=screen.availwidth ;
var winheight=screen.availheight-20;
window.open(“main.aspx”,”surveywindow”,”toolbar=no,width=”+ winwidth  +”,height=”+ winheight  +”,top=0,left=0,scrollbars=yes,resizable=yes,center:yes,statusbars=yes”);
break
//脚本中中使用xml
function initialize() {
  var xmldoc
  var xsldoc

  xmldoc = new activexobject(microsoft.xmldom)
  xmldoc.async = false;

  xsldoc = new activexobject(microsoft.xmldom)
  xsldoc.async = false;

 xmldoc.load(“tree.xml”)
  xsldoc.load(“tree.xsl”)
 
 
  foldertree.innerhtml = xmldoc.documentelement.transformnode(xsldoc)
}

一、验证类
1、数字验证内
  1.1 整数
  1.2 大于0的整数 (用于传来的id的验证)
  1.3 负整数的验证
  1.4 整数不能大于imax
  1.5 整数不能小于imin
2、时间类
  2.1 短时间,形如 (13:04:06)
  2.2 短日期,形如 (2003-12-05)
  2.3 长时间,形如 (2003-12-05 13:04:06)
  2.4 只有年和月。形如(2003-05,或者2003-5)
  2.5 只有小时和分钟,形如(12:03)
3、表单类
  3.1 所有的表单的值都不能为空
  3.2 多行文本框的值不能为空。
  3.3 多行文本框的值不能超过smaxstrleng
  3.4 多行文本框的值不能少于smixstrleng
  3.5 判断单选框是否选择。
  3.6 判断复选框是否选择.
  3.7 复选框的全选,多选,全不选,反选
  3.8 文件上传过程中判断文件类型
4、字符类
  4.1 判断字符全部由a-z或者是a-z的字字母组成
  4.2 判断字符由字母和数字组成。
  4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
  4.4 字符串替换函数.replace();
5、浏览器类
  5.1 判断浏览器的类型
  5.2 判断ie的版本
  5.3 判断客户端的分辨率
 
6、结合类
  6.1 email的判断。
  6.2 手机号码的验证
  6.3 身份证的验证
 

二、功能类

1、时间与相关控件类
  1.1 日历
  1.2 时间控件
  1.3 万年历
  1.4 显示动态显示时钟效果(文本,如oa中时间)
  1.5 显示动态显示时钟效果 (图像,像手表)
2、表单类
  2.1 自动生成表单
  2.2 动态添加,修改,删除下拉框中的元素
  2.3 可以输入内容的下拉框
  2.4 多行文本框中只能输入imax文字。如果多输入了,自动减少到imax个文字(多用于短信发送)
 
3、打印类
  3.1 打印控件
4、事件类
  4.1 屏蔽右键
  4.2 屏蔽所有功能键
  4.3 –> 和<– f5 f11,f9,f1
  4.4 屏蔽组合键ctrl+n
5、网页设计类
  5.1 连续滚动的文字,图片(注意是连续的,两段文字和图片中没有空白出现)
  5.2 html编辑控件类
  5.3 颜色选取框控件
  5.4 下拉菜单
  5.5 两层或多层次的下拉菜单
  5.6 仿ie菜单的按钮。(效果如rongshuxa.com的导航栏目)
  5.7 状态栏,title栏的动态效果(例子很多,可以研究一下)
  5.8 双击后,网页自动滚屏
6、树型结构。
  6.1 asp+sql版
  6.2 asp+xml+sql版
  6.3 java+sql或者java+sql+xml
7、无边框效果的制作
8、连动下拉框技术
9、文本排序
10,画图类,含饼、柱、矢量贝滋曲线
11,操纵客户端注册表类
12,div层相关(拖拽、显示、隐藏、移动、增加)
13,tablae相关(客户端动态增加行列,模拟进度条,滚动列表等)
14,各种<object classid=>相关类,如播放器,flash与脚本互动等
16, 刷新/模拟无刷新 异步调用类(xmlhttp或iframe,frame)

 

 

一、验证类
1、数字验证内
  1.1 整数
      /^(-|\+)?\d+$/.test(str)
  1.2 大于0的整数 (用于传来的id的验证)
      /^\d+$/.test(str)
  1.3 负整数的验证
      /^-\d+$/.test(str)
2、时间类
  2.1 短时间,形如 (13:04:06)
      function istime(str)
      {
        var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
        if (a == null) {alert(输入的参数不是时间格式); return false;}
        if (a[1]>24 || a[3]>60 || a[4]>60)
        {
          alert(“时间格式不对”);
          return false
        }
        return true;
      }
  2.2 短日期,形如 (2003-12-05)
      function strdatetime(str)
      {
         var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
         if(r==null)return false;
         var d= new date(r[1], r[3]-1, r[4]);
         return (d.getfullyear()==r[1]&&(d.getmonth()+1)==r[3]&&d.getdate()==r[4]);
      }
  2.3 长时间,形如 (2003-12-05 13:04:06)
      function strdatetime(str)
      {
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
        var r = str.match(reg);
        if(r==null)return false;
        var d= new date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
        return (d.getfullyear()==r[1]&&(d.getmonth()+1)==r[3]&&d.getdate()==r[4]&&d.gethours()==r[5]&&d.getminutes()==r[6]&&d.getseconds()==r[7]);
      }
  2.4 只有年和月。形如(2003-05,或者2003-5)
  2.5 只有小时和分钟,形如(12:03)
3、表单类
  3.1 所有的表单的值都不能为空
      <input onblur=”if(this.value.replace(/^ +| +$/g,)==)alert(不能为空!)”>
  3.2 多行文本框的值不能为空。
  3.3 多行文本框的值不能超过smaxstrleng
  3.4 多行文本框的值不能少于smixstrleng
  3.5 判断单选框是否选择。
  3.6 判断复选框是否选择.
  3.7 复选框的全选,多选,全不选,反选
  3.8 文件上传过程中判断文件类型
4、字符类
  4.1 判断字符全部由a-z或者是a-z的字字母组成
      <input onblur=”if(/[^a-za-z]/g.test(this.value))alert(有错)”>
  4.2 判断字符由字母和数字组成。
      <input onblur=”if(/[^0-9a-za-z]/g.test(this.value))alert(有错)”>
  4.3 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
      /^([a-za-z_]{1})([\w]*)$/g.test(str)
  4.4 字符串替换函数.replace();
5、浏览器类
  5.1 判断浏览器的类型
      window.navigator.appname
  5.2 判断ie的版本
      window.navigator.appversion
  5.3 判断客户端的分辨率
      window.screen.height;  window.screen.width;
 
6、结合类
  6.1 email的判断。
      function ismail(mail)
      {
        return(new regexp(/^\w+((-\w+)|(\.\w+))*\@[a-za-z0-9]+((\.|-)[a-za-z0-9]+)*\.[a-za-z0-9]+$/).test(mail));
      }
  6.2 手机号码的验证
  6.3 身份证的验证
      function isidcardno(num)
      {
        if (isnan(num)) {alert(“输入的不是数字!”); return false;}
        var len = num.length, re;
        if (len == 15)
          re = new regexp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
        else if (len == 18)
          re = new regexp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);
        else {alert(“输入的数字位数不对!”); return false;}
        var a = num.match(re);
        if (a != null)
        {
          if (len==15)
          {
            var d = new date(“19″+a[3]+”/”+a[4]+”/”+a[5]);
            var b = d.getyear()==a[3]&&(d.getmonth()+1)==a[4]&&d.getdate()==a[5];
          }
          else
          {
            var d = new date(a[3]+”/”+a[4]+”/”+a[5]);
            var b = d.getfullyear()==a[3]&&(d.getmonth()+1)==a[4]&&d.getdate()==a[5];
          }
          if (!b) {alert(“输入的身份证号 “+ a[0] +” 里出生日期不对!”); return false;}
        }
        return true;
      }

画图:
<object
id=s
style=”left: 0px; width: 392px; top: 0px; height: 240px”
height=240
width=392
classid=”clsid:369303c2-d7ac-11d0-89d5-00a0c90833e6″>
</object>
<script>
s.drawingsurface.arcdegrees(0,0,0,30,50,60);
s.drawingsurface.arcradians(30,0,0,30,50,60);
s.drawingsurface.line(10,10,100,100);
</script>

写注册表:
<script>
var wshshell = wscript.createobject(“wscript.shell”);
wshshell.regwrite (“hkcu\ oftware\\acme\\fortuneteller\\”, 1, “reg_binary”);
wshshell.regwrite (“hkcu\ oftware\\acme\\fortuneteller\\mindreader”, “goocher!”, “reg_sz”);
var bkey =    wshshell.regread (“hkcu\ oftware\\acme\\fortuneteller\\”);
wscript.echo (wshshell.regread (“hkcu\ oftware\\acme\\fortuneteller\\mindreader”));
wshshell.regdelete (“hkcu\ oftware\\acme\\fortuneteller\\mindreader”);
wshshell.regdelete (“hkcu\ oftware\\acme\\fortuneteller\\”);
wshshell.regdelete (“hkcu\ oftware\\acme\\”);
</script>

 

 

tablae相关(客户端动态增加行列)
<html>
<script language=”jscript”>
function numbercells() {
    var count=0;
    for (i=0; i < document.all.mytable.rows.length; i++) {
        for (j=0; j < document.all.mytable.rows(i).cells.length; j++) {
            document.all.mytable.rows(i).cells(j).innertext = count;
            count++;
        }
    }
}
</script>
<body onload=”numbercells()”>
<table id=mytable border=1>
<tr><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>
</body>
</html>

 

 

1.身份证严格验证:

<script>
var acity={11:”北京”,12:”天津”,13:”河北”,14:”山西”,15:”内蒙古”,21:”辽宁”,22:”吉林”,23:”黑龙江”,31:”上海”,32:”江苏”,33:”浙江”,34:”安徽”,35:”福建”,36:”江西”,37:”山东”,41:”河南”,42:”湖北”,43:”湖南”,44:”广东”,45:”广西”,46:”海南”,50:”重庆”,51:”四川”,52:”贵州”,53:”云南”,54:”西藏”,61:”陕西”,62:”甘肃”,63:”青海”,64:”宁夏”,65:”新疆”,71:”台湾”,81:”香港”,82:”澳门”,91:”国外”}
 
function cidinfo(sid){
var isum=0
var info=””
if(!/^\d{17}(\d|x)$/i.test(sid))return false;
sid=sid.replace(/x$/i,”a”);
if(acity[parseint(sid.substr(0,2))]==null)return “error:非法地区”;
sbirthday=sid.substr(6,4)+”-“+number(sid.substr(10,2))+”-“+number(sid.substr(12,2));
var d=new date(sbirthday.replace(/-/g,”/”))
if(sbirthday!=(d.getfullyear()+”-“+ (d.getmonth()+1) + “-” + d.getdate()))return “error:非法生日”;
for(var i = 17;i>=0;i –) isum += (math.pow(2,i) % 11) * parseint(sid.charat(17 – i),11)
if(isum%11!=1)return “error:非法证号”;
return acity[parseint(sid.substr(0,2))]+”,”+sbirthday+”,”+(sid.substr(16,1)%2?”男”:”女”)
}

document.write(cidinfo(“380524198002300016″),”<br/>”);
document.write(cidinfo(“340524198002300019″),”<br/>”)
document.write(cidinfo(“340524197711111111″),”<br/>”)
document.write(cidinfo(“34052419800101001x”),”<br/>”);
</script>

2.验证ip地址
<script language=”javascript”>
function isip(s){
var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
var re=s.split(“.”)
return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}

var s=”202.197.78.129″;
alert(isip(s))
</script>

 

3.加sp1后还能用的无边框窗口!!
<html xmlns:ie>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″>
<ie:download id=”include” style=”behavior:url(#default#download)” />
<title>chromeless window</title>

<script language=”jscript”>
/*— special thanks for andot —*/

/*
 this following code are designed and writen by windy_sk <seasonx@163.net>
 you can use it freely, but u must held all the copyright items!
*/

/*— thanks for andot again —*/

var cw_width= 400;
var cw_height= 300;
var cw_top= 100;
var cw_left= 100;
var cw_url= “/”;
var new_cw= window.createpopup();
var cw_body= new_cw.document.body;
var content= “”;
var csstext= “margin:1px;color:black; border:2px outset;border-style:expression(onmouseout=onmouseup=function(){this.style.borderstyle=outset}, onmousedown=function(){if(event.button!=2)this.style.borderstyle=inset});background-color:buttonface;width:16px;height:14px;font-size:12px;line-height:11px;cursor:default;”;

//build window
include.startdownload(cw_url, function(source){content=source});

function insert_content(){
var temp = “”;
cw_body.style.overflow= “hidden”;
cw_body.style.backgroundcolor= “white”;
cw_body.style.border=  “solid black 1px”;
content = content.replace(/<a ([^>]*)>/g,”<a onclick=parent.open(this.href);return false $1>”);
temp += “<table width=100% height=100% cellpadding=0 cellspacing=0 border=0>”;
temp += “<tr style=;font-size:12px;background:#0099cc;height:20;cursor:default ondblclick=\”max.innertext=max.innertext==1?2:1;parent.if_max=!parent.if_max;parent.show_cw();\” onmouseup=parent.drag_up(event) onmousemove=parent.drag_move(event) onmousedown=parent.drag_down(event) onselectstart=return false oncontextmenu=return false>”;
temp += “<td style=color:#ffffff;padding-left:5px>chromeless window for ie6 sp1</td>”;
temp += “<td style=color:#ffffff;padding-right:5px; align=right>”;
temp += “<span id=help  onclick=\”alert(chromeless window for ie6 sp1  –  ver 1.0\\n\\ncode by windy_sk\\n\\nspecial thanks for andot)\” style=\””+csstext+”font-family:system;padding-right:2px;\”>?</span>”;
temp += “<span id=min   onclick=parent.new_cw.hide();parent.blur() style=\””+csstext+”font-family:webdings;\” title=minimum>0</span>”;
temp += “<span id=max   onclick=\”this.innertext=this.innertext==1?2:1;parent.if_max=!parent.if_max;parent.show_cw();\” style=\””+csstext+”font-family:webdings;\” title=maximum>1</span>”;
temp += “<span id=close onclick=parent.opener=null;parent.close() style=\””+csstext+”font-family:system;padding-right:2px;\” title=close>x</span>”;
temp += “</td></tr><tr><td colspan=2>”;
temp += “<div id=include style=overflow:scroll;overflow-x:hidden;overflow-y:auto; height: 100%; width:”+cw_width+”>”;
temp += content;
temp += “</div>”;
temp += “</td></tr></table>”;
cw_body.innerhtml = temp;
}

settimeout(“insert_content()”,1000);

var if_max = true;
function show_cw(){
window.moveto(10000, 10000);
if(if_max){
new_cw.show(cw_top, cw_left, cw_width, cw_height);
if(typeof(new_cw.document.all.include)!=”undefined”){
new_cw.document.all.include.style.width = cw_width;
new_cw.document.all.max.innertext = “1”;
}

}else{
new_cw.show(0, 0, screen.width, screen.height);
new_cw.document.all.include.style.width = screen.width;
}
}

window.onfocus  = show_cw;
window.onresize = show_cw;

// move window
var drag_x,drag_y,draging=false

function drag_move(e){
if (draging){
new_cw.show(e.screenx-drag_x, e.screeny-drag_y, cw_width, cw_height);
return false;
}
}

function drag_down(e){
if(e.button==2)return;
if(new_cw.document.body.offsetwidth==screen.width && new_cw.document.body.offsetheight==screen.height)return;
drag_x=e.clientx;
drag_y=e.clienty;
draging=true;
e.srcelement.setcapture();
}

function drag_up(e){
draging=false;
e.srcelement.releasecapture();
if(new_cw.document.body.offsetwidth==screen.width && new_cw.document.body.offsetheight==screen.height) return;
cw_top  = e.screenx-drag_x;
cw_left = e.screeny-drag_y;
}

</script>
</html>

贴两个关于treeview的
  <script language=”javascript”>
<!–
//初始化选中节点
function initchecknode()
{
 var node=treeview1.gettreenode(“1”);
 node.setattribute(“checked”,”true”);
 setcheck(node,”true”);
 findcheckedfromnode(treeview1);
}
//oncheck事件
function tree_oncheck(tree)
{
 var node=tree.gettreenode(tree.clickednodeindex);
 var pchecked=tree.gettreenode(tree.clickednodeindex).getattribute(“checked”);
 setcheck(node,pchecked);
 document.all.checked.value=””;
 document.all.unchecked.value=””;
 findcheckedfromnode(treeview1);
}
//设置子节点选中
function setcheck(node,pc)
{
 var i;
 var childnode=new array();
 childnode=node.getchildren();
 
 if(parseint(childnode.length)==0)
  return;
 else
 {
  for(i=0;i<childnode.length;i++)
  {
   var cnode;
   cnode=childnode[i];
   if(parseint(cnode.getchildren().length)!=0)
    setcheck(cnode,pc);
   cnode.setattribute(“checked”,pc);
  }
 }
}
//获取所有节点状态
function findcheckedfromnode(node) {
 var i = 0;
 var nodes = new array();
 nodes = node.getchildren();
 
 for (i = 0; i < nodes.length; i++) {
  var cnode;
  cnode=nodes[i];
  if (cnode.getattribute(“checked”))
   addchecked(cnode);
  else
      addunchecked(cnode);
 
  if (parseint(cnode.getchildren().length) != 0 ) {
   findcheckedfromnode(cnode);
  }
 }
}
//添加选中节点
function addchecked(node) {
 document.all.checked.value += node.getattribute(“nodedata”);
 document.all.checked.value += ,;
}
//添加未选中节点
function addunchecked(node) {
 document.all.unchecked.value += node.getattribute(“nodedata”);
 document.all.unchecked.value += ,;
}
//–>
  </script>

treeview中如何在服务器端得到客户端设置后的节点选中状态
 <script language=”c#” runat=”server”>
   private void button1_click(object sender, system.eventargs e)
   {
    response.write(treeview1.nodes[0].checked);
   }
  </script>
  <script language=”javascript”>
   function set_check()
   {
    var nodeindex = “0”;
    var node=treeview1.gettreenode(nodeindex);
    node.setattribute(“checked”,”true”);
    treeview1.queueevent(oncheck, nodeindex);
   }
  </script>

三個實用的小技巧:關閉輸入法.禁止貼上.禁止複製
關閉輸入法

本文字框輸入法被關閉: 
語法: style=”ime-mode:disabled”
範例: <input type=”text” name=”textfield” style=”ime-mode:disabled”>

禁止貼上

本文字框禁止貼上文字: 
語法:onpaste=”return false”
範例:<input type=”text” name=”textfield” onpaste=”return false”>

禁止複製

本文字框禁止複製: 
語法:oncopy=”return false;” oncut=”return false;”
範例:<input name=”textfield” type=”text” value=”不能複製裡面的字” oncopy=”return false;” oncut=”return false;”>

//================================
//cookie操作
//================================
function getcookieval (offset)
{
var endstr = document.cookie.indexof (“;”, offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function getcookie (name)
{
var arg = name + “=”;
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getcookieval (j);
i = document.cookie.indexof(” “, i) + 1;
if (i == 0)
break;
}
return null;
}

function deletecookie(cname) {

  var expdate = new date();
  expdate.settime(expdate.gettime() – (24 * 60 * 60 * 1000 * 369));

 // document.cookie =” ckvalue=”ok”; expires=”+ expdate.togmtstring();
  setcookie(cname,””,expdate);

}

function setcookie (name, value, expires) {

  document.cookie = name + “=” + escape(value) +
    “; expires=” + expires.togmtstring() ;
}

 

一个可以在页面上随意画线、多边形、圆,填充等功能的js  (part 1)

var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz,
jg_n4 = (document.layers && typeof document.classes != “undefined”);

function chkdhtm(x, i)
{
x = document.body || null;
jg_ie = x && typeof x.insertadjacenthtml != “undefined”;
jg_dom = (x && !jg_ie &&
typeof x.appendchild != “undefined” &&
typeof document.createrange != “undefined” &&
typeof (i = document.createrange()).setstartbefore != “undefined” &&
typeof i.createcontextualfragment != “undefined”);
jg_ihtm = !jg_ie && !jg_dom && x && typeof x.innerhtml != “undefined”;
jg_fast = jg_ie && document.all && !window.opera;
jg_moz = jg_dom && typeof x.style.mozopacity != “undefined”;
}

function pntdoc()
{
this.wnd.document.write(jg_fast? this.htmrpc() : this.htm);
this.htm = ;
}

function pntcnvdom()
{
var x = document.createrange();
x.setstartbefore(this.cnv);
x = x.createcontextualfragment(jg_fast? this.htmrpc() : this.htm);
this.cnv.appendchild(x);
this.htm = ;
}

function pntcnvie()
{
this.cnv.insertadjacenthtml(“beforeend”, jg_fast? this.htmrpc() : this.htm);
this.htm = ;
}

function pntcnvihtm()
{
this.cnv.innerhtml += this.htm;
this.htm = ;
}

function pntcnv()
{
this.htm = ;
}

function mkdiv(x, y, w, h)
{
this.htm += <div style=”position:absolute;+
left: + x + px;+
top: + y + px;+
width: + w + px;+
height: + h + px;+
clip:rect(0,+w+px,+h+px,0);+
background-color: + this.color +
(!jg_moz? ;overflow:hidden : )+
;”><\/div>;
}

function mkdivie(x, y, w, h)
{
this.htm += %%+this.color+;+x+;+y+;+w+;+h+;;
}

function mkdivprt(x, y, w, h)
{
this.htm += <div style=”position:absolute;+
border-left: + w + px solid + this.color + ;+
left: + x + px;+
top: + y + px;+
width:0px;+
height: + h + px;+
clip:rect(0,+w+px,+h+px,0);+
background-color: + this.color +
(!jg_moz? ;overflow:hidden : )+
;”><\/div>;
}

function mklyr(x, y, w, h)
{
this.htm += <layer +
left=” + x + ” +
top=” + y + ” +
width=” + w + ” +
height=” + h + ” +
bgcolor=” + this.color + “><\/layer>\n;
}

var regex =  /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;
function htmrpc()
{
return this.htm.replace(
regex,
<div style=”overflow:hidden;position:absolute;background-color:+
$1;left:$2;top:$3;width:$4;height:$5″></div>\n);
}

function htmprtrpc()
{
return this.htm.replace(
regex,
<div style=”overflow:hidden;position:absolute;background-color:+
$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1″></div>\n);
}

function mklin(x1, y1, x2, y2)
{
if (x1 > x2)
{
var _x2 = x2;
var _y2 = y2;
x2 = x1;
y2 = y1;
x1 = _x2;
y1 = _y2;
}
var dx = x2-x1, dy = math.abs(y2-y1),
x = x1, y = y1,
yincr = (y1 > y2)? -1 : 1;

if (dx >= dy)
{
var pr = dy<<1,
pru = pr – (dx<<1),
p = pr-dx,
ox = x;
while ((dx–) > 0)
{
++x;
if (p > 0)
{
this.mkdiv(ox, y, x-ox, 1);
y += yincr;
p += pru;
ox = x;
}
else p += pr;
}
this.mkdiv(ox, y, x2-ox+1, 1);
}

else
{
var pr = dx<<1,
pru = pr – (dy<<1),
p = pr-dy,
oy = y;
if (y2 <= y1)
{
while ((dy–) > 0)
{
if (p > 0)
{
this.mkdiv(x++, y, 1, oy-y+1);
y += yincr;
p += pru;
oy = y;
}
else
{
y += yincr;
p += pr;
}
}
this.mkdiv(x2, y2, 1, oy-y2+1);
}
else
{
while ((dy–) > 0)
{
y += yincr;
if (p > 0)
{
this.mkdiv(x++, oy, 1, y-oy);
p += pru;
oy = y;
}
else p += pr;
}
this.mkdiv(x2, oy, 1, y2-oy+1);
}
}
}

function mklin2d(x1, y1, x2, y2)
{
if (x1 > x2)
{
var _x2 = x2;
var _y2 = y2;
x2 = x1;
y2 = y1;
x1 = _x2;
y1 = _y2;
}
var dx = x2-x1, dy = math.abs(y2-y1),
x = x1, y = y1,
yincr = (y1 > y2)? -1 : 1;

var s = this.stroke;
if (dx >= dy)
{
if (s-3 > 0)
{
var _s = (s*dx*math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
_s = (!(s-4)? math.ceil(_s) : math.round(_s)) + 1;
}
else var _s = s;
var ad = math.ceil(s/2);

var pr = dy<<1,
pru = pr – (dx<<1),
p = pr-dx,
ox = x;
while ((dx–) > 0)
{
++x;
if (p > 0)
{
this.mkdiv(ox, y, x-ox+ad, _s);
y += yincr;
p += pru;
ox = x;
}
else p += pr;
}
this.mkdiv(ox, y, x2-ox+ad+1, _s);
}

else
{
if (s-3 > 0)
{
var _s = (s*dy*math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
_s = (!(s-4)? math.ceil(_s) : math.round(_s)) + 1;
}
else var _s = s;
var ad = math.round(s/2);

var pr = dx<<1,
pru = pr – (dy<<1),
p = pr-dy,
oy = y;
if (y2 <= y1)
{
++ad;
while ((dy–) > 0)
{
if (p > 0)
{
this.mkdiv(x++, y, _s, oy-y+ad);
y += yincr;
p += pru;
oy = y;
}
else
{
y += yincr;
p += pr;
}
}
this.mkdiv(x2, y2, _s, oy-y2+ad);
}
else
{
while ((dy–) > 0)
{
y += yincr;
if (p > 0)
{
this.mkdiv(x++, oy, _s, y-oy+ad);
p += pru;
oy = y;
}
else p += pr;
}
this.mkdiv(x2, oy, _s, y2-oy+ad+1);
}
}
}

function mklindott(x1, y1, x2, y2)
{
if (x1 > x2)
{
var _x2 = x2;
var _y2 = y2;
x2 = x1;
y2 = y1;
x1 = _x2;
y1 = _y2;
}
var dx = x2-x1, dy = math.abs(y2-y1),
x = x1, y = y1,
yincr = (y1 > y2)? -1 : 1,
drw = true;
if (dx >= dy)
{
var pr = dy<<1,
pru = pr – (dx<<1),
p = pr-dx;
while ((dx–) > 0)
{
if (drw) this.mkdiv(x, y, 1, 1);
drw = !drw;
if (p > 0)
{
y += yincr;
p += pru;
}
else p += pr;
++x;
}
if (drw) this.mkdiv(x, y, 1, 1);
}

else
{
var pr = dx<<1,
pru = pr – (dy<<1),
p = pr-dy;
while ((dy–) > 0)
{
if (drw) this.mkdiv(x, y, 1, 1);
drw = !drw;
y += yincr;
if (p > 0)
{
++x;
p += pru;
}
else p += pr;
}
if (drw) this.mkdiv(x, y, 1, 1);
}
}

function mkov(left, top, width, height)
{
var a = width>>1, b = height>>1,
wod = width&1, hod = (height&1)+1,
cx = left+a, cy = top+b,
x = 0, y = b,
ox = 0, oy = b,
aa = (a*a)<<1, bb = (b*b)<<1,
st = (aa>>1)*(1-(b<<1)) + bb,
tt = (bb>>1) – aa*((b<<1)-1),
w, h;
while (y > 0)
{
if (st < 0)
{
st += bb*((x<<1)+3);
tt += (bb<<1)*(++x);
}
else if (tt < 0)
{
st += bb*((x<<1)+3) – (aa<<1)*(y-1);
tt += (bb<<1)*(++x) – aa*(((y–)<<1)-3);
w = x-ox;
h = oy-y;
if (w&2 && h&2)
{
this.mkovqds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1);
this.mkovqds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
}
else this.mkovqds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);
ox = x;
oy = y;
}
else
{
tt -= aa*((y<<1)-3);
st -= (aa<<1)*(–y);
}
}
this.mkdiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
this.mkdiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
}

一个可以在页面上随意画线、多边形、圆,填充等功能的js  (part 2)

function mkov2d(left, top, width, height)
{
var s = this.stroke;
width += s-1;
height += s-1;
var a = width>>1, b = height>>1,
wod = width&1, hod = (height&1)+1,
cx = left+a, cy = top+b,
x = 0, y = b,
aa = (a*a)<<1, bb = (b*b)<<1,
st = (aa>>1)*(1-(b<<1)) + bb,
tt = (bb>>1) – aa*((b<<1)-1);

if (s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0))
{
var ox = 0, oy = b,
w, h,
pxl, pxr, pxt, pxb, pxw;
while (y > 0)
{
if (st < 0)
{
st += bb*((x<<1)+3);
tt += (bb<<1)*(++x);
}
else if (tt < 0)
{
st += bb*((x<<1)+3) – (aa<<1)*(y-1);
tt += (bb<<1)*(++x) – aa*(((y–)<<1)-3);
w = x-ox;
h = oy-y;

if (w-1)
{
pxw = w+1+(s&1);
h = s;
}
else if (h-1)
{
pxw = s;
h += 1+(s&1);
}
else pxw = h = s;
this.mkovqds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);
ox = x;
oy = y;
}
else
{
tt -= aa*((y<<1)-3);
st -= (aa<<1)*(–y);
}
}
this.mkdiv(cx-a, cy-oy, s, (oy<<1)+hod);
this.mkdiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod);
}

else
{
var _a = (width-((s-1)<<1))>>1,
_b = (height-((s-1)<<1))>>1,
_x = 0, _y = _b,
_aa = (_a*_a)<<1, _bb = (_b*_b)<<1,
_st = (_aa>>1)*(1-(_b<<1)) + _bb,
_tt = (_bb>>1) – _aa*((_b<<1)-1),

pxl = new array(),
pxt = new array(),
_pxb = new array();
pxl[0] = 0;
pxt[0] = b;
_pxb[0] = _b-1;
while (y > 0)
{
if (st < 0)
{
st += bb*((x<<1)+3);
tt += (bb<<1)*(++x);
pxl[pxl.length] = x;
pxt[pxt.length] = y;
}
else if (tt < 0)
{
st += bb*((x<<1)+3) – (aa<<1)*(y-1);
tt += (bb<<1)*(++x) – aa*(((y–)<<1)-3);
pxl[pxl.length] = x;
pxt[pxt.length] = y;
}
else
{
tt -= aa*((y<<1)-3);
st -= (aa<<1)*(–y);
}

if (_y > 0)
{
if (_st < 0)
{
_st += _bb*((_x<<1)+3);
_tt += (_bb<<1)*(++_x);
_pxb[_pxb.length] = _y-1;
}
else if (_tt < 0)
{
_st += _bb*((_x<<1)+3) – (_aa<<1)*(_y-1);
_tt += (_bb<<1)*(++_x) – _aa*(((_y–)<<1)-3);
_pxb[_pxb.length] = _y-1;
}
else
{
_tt -= _aa*((_y<<1)-3);
_st -= (_aa<<1)*(–_y);
_pxb[_pxb.length-1]–;
}
}
}

var ox = 0, oy = b,
_oy = _pxb[0],
l = pxl.length,
w, h;
for (var i = 0; i < l; i++)
{
if (typeof _pxb[i] != “undefined”)
{
if (_pxb[i] < _oy || pxt[i] < oy)
{
x = pxl[i];
this.mkovqds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);
ox = x;
oy = pxt[i];
_oy = _pxb[i];
}
}
else
{
x = pxl[i];
this.mkdiv(cx-x+1, cy-oy, 1, (oy<<1)+hod);
this.mkdiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
ox = x;
oy = pxt[i];
}
}
this.mkdiv(cx-a, cy-oy, 1, (oy<<1)+hod);
this.mkdiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
}
}

function mkovdott(left, top, width, height)
{
var a = width>>1, b = height>>1,
wod = width&1, hod = height&1,
cx = left+a, cy = top+b,
x = 0, y = b,
aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
st = (aa2>>1)*(1-(b<<1)) + bb,
tt = (bb>>1) – aa2*((b<<1)-1),
drw = true;
while (y > 0)
{
if (st < 0)
{
st += bb*((x<<1)+3);
tt += (bb<<1)*(++x);
}
else if (tt < 0)
{
st += bb*((x<<1)+3) – aa4*(y-1);
tt += (bb<<1)*(++x) – aa2*(((y–)<<1)-3);
}
else
{
tt -= aa2*((y<<1)-3);
st -= aa4*(–y);
}
if (drw) this.mkovqds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);
drw = !drw;
}
}

一个可以在页面上随意画线、多边形、圆,填充等功能的js  (part 3)

function mkrect(x, y, w, h)
{
var s = this.stroke;
this.mkdiv(x, y, w, s);
this.mkdiv(x+w, y, s, h);
this.mkdiv(x, y+h, w+s, s);
this.mkdiv(x, y+s, s, h-s);
}

function mkrectdott(x, y, w, h)
{
this.drawline(x, y, x+w, y);
this.drawline(x+w, y, x+w, y+h);
this.drawline(x, y+h, x+w, y+h);
this.drawline(x, y, x, y+h);
}

function jsgfont()
{
this.plain = font-weight:normal;;
this.bold = font-weight:bold;;
this.italic = font-style:italic;;
this.italic_bold = this.italic + this.bold;
this.bold_italic = this.italic_bold;
}
var font = new jsgfont();

function jsgstroke()
{
this.dotted = -1;
}
var stroke = new jsgstroke();

function jsgraphics(id, wnd)
{
this.setcolor = new function(arg, this.color = arg.tolowercase(););

this.setstroke = function(x)
{
this.stroke = x;
if (!(x+1))
{
this.drawline = mklindott;
this.mkov = mkovdott;
this.drawrect = mkrectdott;
}
else if (x-1 > 0)
{
this.drawline = mklin2d;
this.mkov = mkov2d;
this.drawrect = mkrect;
}
else
{
this.drawline = mklin;
this.mkov = mkov;
this.drawrect = mkrect;
}
};

this.setprintable = function(arg)
{
this.printable = arg;
if (jg_fast)
{
this.mkdiv = mkdivie;
this.htmrpc = arg? htmprtrpc : htmrpc;
}
else this.mkdiv = jg_n4? mklyr : arg? mkdivprt : mkdiv;
};

this.setfont = function(fam, sz, sty)
{
this.ftfam = fam;
this.ftsz = sz;
this.ftsty = sty || font.plain;
};

this.drawpolyline = this.drawpolyline = function(x, y, s)
{
for (var i=0 ; i<x.length-1 ; i++ )
this.drawline(x[i], y[i], x[i+1], y[i+1]);
};

this.fillrect = function(x, y, w, h)
{
this.mkdiv(x, y, w, h);
};

this.drawpolygon = function(x, y)
{
this.drawpolyline(x, y);
this.drawline(x[x.length-1], y[x.length-1], x[0], y[0]);
};

this.drawellipse = this.drawoval = function(x, y, w, h)
{
this.mkov(x, y, w, h);
};

this.fillellipse = this.filloval = function(left, top, w, h)
{
var a = (w -= 1)>>1, b = (h -= 1)>>1,
wod = (w&1)+1, hod = (h&1)+1,
cx = left+a, cy = top+b,
x = 0, y = b,
ox = 0, oy = b,
aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
st = (aa2>>1)*(1-(b<<1)) + bb,
tt = (bb>>1) – aa2*((b<<1)-1),
pxl, dw, dh;
if (w+1) while (y > 0)
{
if (st < 0)
{
st += bb*((x<<1)+3);
tt += (bb<<1)*(++x);
}
else if (tt < 0)
{
st += bb*((x<<1)+3) – aa4*(y-1);
pxl = cx-x;
dw = (x<<1)+wod;
tt += (bb<<1)*(++x) – aa2*(((y–)<<1)-3);
dh = oy-y;
this.mkdiv(pxl, cy-oy, dw, dh);
this.mkdiv(pxl, cy+oy-dh+hod, dw, dh);
ox = x;
oy = y;
}
else
{
tt -= aa2*((y<<1)-3);
st -= aa4*(–y);
}
}
this.mkdiv(cx-a, cy-oy, w+1, (oy<<1)+hod);
};

this.fillpolygon = function(array_x, array_y)
{
var i;
var y;
var miny, maxy;
var x1, y1;
var x2, y2;
var ind1, ind2;
var ints;

var n = array_x.length;

if (!n) return;

miny = array_y[0];
maxy = array_y[0];
for (i = 1; i < n; i++)
{
if (array_y[i] < miny)
miny = array_y[i];

if (array_y[i] > maxy)
maxy = array_y[i];
}
for (y = miny; y <= maxy; y++)
{
var polyints = new array();
ints = 0;
for (i = 0; i < n; i++)
{
if (!i)
{
ind1 = n-1;
ind2 = 0;
}
else
{
ind1 = i-1;
ind2 = i;
}
y1 = array_y[ind1];
y2 = array_y[ind2];
if (y1 < y2)
{
x1 = array_x[ind1];
x2 = array_x[ind2];
}
else if (y1 > y2)
{
y2 = array_y[ind1];
y1 = array_y[ind2];
x2 = array_x[ind1];
x1 = array_x[ind2];
}
else continue;

if ((y >= y1) && (y < y2))
polyints[ints++] = math.round((y-y1) * (x2-x1) / (y2-y1) + x1);

else if ((y == maxy) && (y > y1) && (y <= y2))
polyints[ints++] = math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
}
polyints.sort(integer_compare);

for (i = 0; i < ints; i+=2)
{
w = polyints[i+1]-polyints[i]
this.mkdiv(polyints[i], y, polyints[i+1]-polyints[i]+1, 1);
}
}
};

this.drawstring = function(txt, x, y)
{
this.htm += <div style=”position:absolute;white-space:nowrap;+
left: + x + px;+
top: + y + px;+
font-family: +  this.ftfam + ;+
font-size: + this.ftsz + ;+
color: + this.color + ; + this.ftsty + “>+
txt +
<\/div>;
}

this.drawimage = function(imgsrc, x, y, w, h)
{
this.htm += <div style=”position:absolute;+
left: + x + px;+
top: + y + px;+
width: +  w + ;+
height: + h + ;”>+
<img src=” + imgsrc + ” width=” + w + ” height=” + h + “>+
<\/div>;
}

this.clear = function()
{
this.htm = “”;
if (this.cnv) this.cnv.innerhtml = this.defhtm;
};

this.mkovqds = function(cx, cy, xl, xr, yt, yb, w, h)
{
this.mkdiv(xr+cx, yt+cy, w, h);
this.mkdiv(xr+cx, yb+cy, w, h);
this.mkdiv(xl+cx, yb+cy, w, h);
this.mkdiv(xl+cx, yt+cy, w, h);
};

this.setstroke(1);
this.setfont(verdana,geneva,helvetica,sans-serif, string.fromcharcode(0x31, 0x32, 0x70, 0x78), font.plain);
this.color = #000000;
this.htm = ;
this.wnd = wnd || window;

if (!(jg_ie || jg_dom || jg_ihtm)) chkdhtm();
if (typeof id != string || !id) this.paint = pntdoc;
else
{
this.cnv = document.all? (this.wnd.document.all[id] || null)
: document.getelementbyid? (this.wnd.document.getelementbyid(id) || null)
: null;
this.defhtm = (this.cnv && this.cnv.innerhtml)? this.cnv.innerhtml : ;
this.paint = jg_dom? pntcnvdom : jg_ie? pntcnvie : jg_ihtm? pntcnvihtm : pntcnv;
}

this.setprintable(false);
}

function integer_compare(x,y)
{
return (x < y) ? -1 : ((x > y)*1);
}

 

 

 

 

   js 中,一些东西不可用的三种展现方式。
我们在web项目中,有时候需要在用户点击某个东西的时候,一些东西不可用。如果在客户端实现。最简单的就是利用disabled 。下面罗列的其中三种方式:依次是:不可用(disabled);用一个空白来代替这个地方(blank);这个区域为空(none)。具体可以查看这个blog的源文件:
obj.disabled = false;

obj.style.visibility = “hidden”;

obj.style.display = “none”;

<script language=javascript>
function showdisableobject(obj)
{
 if(obj.disabled == false)
 {
  obj.disabled = true;
 }
 else{
  obj.disabled = false;
 }
 var coll = obj.all.tags(“input”);
 if (coll!=null)
 {
  for (var i=0; i<coll.length; i++)
  {
   coll[i].disabled = obj.disabled;
  }
 }
}

function showblankobject(obj)
{
 if(obj.style.visibility == “hidden”)
 {
  obj.style.visibility = “visible”;
 }
 else
 {
  obj.style.visibility = “hidden”;
 }
}

function shownoneobject(obj)
{
 if(obj.style.display == “none”)
 {
  obj.style.display = “block”;
 }
 else
 {
  obj.style.display = “none”;
 }
}

</script>

<p></p>
<div id=show01>dadd
<div>ccc</div><input> <input type=checkbox> </div>
<p><input onclick=showdisableobject(show01); type=button value=disable> <input id=button1 onclick=showblankobject(show01); type=button value=blank name=button1> <input id=button2 onclick=shownoneobject(show01); type=button value=none name=button2> </p><!–演示代码结束//–>

on this page i explain a simple dhtml example script that features invisibility, moving and the changing of text colour.

example
test textmake test text invisible.
make test text visible.
move test text 50 pixels down.
move test text 50 pixels up.
change colour to red.
change colour to blue.
change colour to black.
change the font style to italic.
change the font style to normal.
change the font family to times.
change the font family to arial.

the script
the scripts work on this html element:

<div id=”text”>test text</div>

#text {position: absolute;
top: 400px;
left: 400px;
font: 18px arial;
font-weight: 700;
}

these scripts are necessary for the three effects:

var dhtml = (document.getelementbyid || document.all || document.layers);

function getobj(name)
{
  if (document.getelementbyid)
  {
  this.obj = document.getelementbyid(name);
this.style = document.getelementbyid(name).style;
  }
  else if (document.all)
  {
this.obj = document.all[name];
this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   this.obj = document.layers[name];
   this.style = document.layers[name];
  }
}

function invi(flag)
{
if (!dhtml) return;
var x = new getobj(text);
x.style.visibility = (flag) ? hidden : visible
}

var texttop = 400;

function move(amount)
{
if (!dhtml) return;
var x = new getobj(text);
texttop += amount;
x.style.top = texttop;
}

function changecol(col)
{
if (!dhtml) return;
var x = new getobj(text);
x.style.color = col;
}

 

一段实现datagrid的“编辑”、“取消”功能脚本,目的是不产生页面刷新
<script language=”javascript”>
var selectrow=””;
var selectobject;
function editcell(thisobject,type)
{
var id = thisobject.id;
var buttonid=”button”+type;
var row=id.replace(buttonid,””);
if(type==1&&selectrow.length>0&&selectobject!=null)
{
editrow(selectrow,2,selectobject);
selectrow=””;
}
if(type==1){selectrow=row;selectobject=thisobject;}else{selectrow=””;selectobject=null;}
editrow(row,type,thisobject);
}

function editrow(row,type,thisobject)
{
var visible1=”none”;
var visible2=”inline”;
if(type!=1)
{
visible1=”inline”;
visible2=”none”;
}
var buttonid=”button”+type;
var style;
var i;
for(i=1;i<8;i++)
{
var name1=row+”img”+i;
document.all[name1].getattribute(“style”).display=visible1;
name1=row+”text”+i;
var name2=row+”checkbox”+i;
document.all[name2].getattribute(“style”).display=visible2;
if(type!=1)
{
if(document.all[name1].value==1)
document.all[name2].checked=true;
else
document.all[name2].checked=false;
}
}

var tdindex = thisobject.parentelement.cellindex;
if(type>1) tdindex = tdindex -1;
thisobject.parentelement.parentelement.cells[tdindex].getattribute(“style”).display=visible2;

thisobject.parentelement.colspan=type;

var name;
name=row+buttonid;
document.all[name].getattribute(“style”).display=”none”;

if(type==1)
{
document.all[name].parentelement.parentelement.getattribute(“style”).backgroundcolor=”lightyellow”;
name=row+”button2″;
document.all[name].getattribute(“style”).display=”inline”;
}
else
{
document.all[name].parentelement.parentelement.getattribute(“style”).backgroundcolor=””;
name=row+”button1″;
document.all[name].getattribute(“style”).display=”inline”;
}
}

</script>
<asp:datagrid id=”griditem” runat=”server” cellpadding=”0″ borderstyle=”solid” autogeneratecolumns=”false”
width=”100%” allowpaging=”true”>
<selecteditemstyle backcolor=”lightyellow”></selecteditemstyle>
<edititemstyle cssclass=”tdbg-dark” backcolor=”ivory”></edititemstyle>
<itemstyle horizontalalign=”center” height=”23px” cssclass=”tdbg”></itemstyle>
<headerstyle horizontalalign=”center” height=”25px” cssclass=”summary-title”></headerstyle>
<columns>
<asp:boundcolumn datafield=”id” readonly=”true” headertext=”人员编号”>
<headerstyle width=”120px”></headerstyle>
</asp:boundcolumn>
<asp:boundcolumn readonly=”true” headertext=”姓名”>
<headerstyle width=”120px”></headerstyle>
</asp:boundcolumn>
<asp:templatecolumn headertext=”管理权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img1″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox1″ style=”display: none” type=”checkbox” runat=”server”>
<input id=”text1″ type=”text” runat=”server” style=”display: none”>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”查询权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img2″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox2″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox2″>
<input id=”text2″ type=”text” runat=”server” style=”display: none” name=”text2″>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”录入权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img3″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox3″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox3″>
<input id=”text3″ type=”text” runat=”server” style=”display: none” name=”text3″>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”修改权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img4″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox4″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox4″>
<input id=”text4″ type=”text” runat=”server” style=”display: none” name=”text4″>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”删除权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img5″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox5″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox5″>
<input id=”text5″ type=”text” runat=”server” style=”display: none” name=”text5″>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”导出权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img6″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox6″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox6″>
<input id=”text6″ type=”text” runat=”server” style=”display: none” name=”text6″>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext=”导入权”>
<headerstyle width=”60px”></headerstyle>
<itemtemplate>
<img id=”img7″ style=”display: inline” alt=”” src=”images/checkboxunselect.gif” runat=”server”><input id=”checkbox7″ style=”display: none” type=”checkbox” runat=”server” name=”checkbox7″>
<input id=”text7″ type=”text” runat=”server” style=”display: none” name=”text7″>
</itemtemplate>
</asp:templatecolumn>
<asp:buttoncolumn text=”保存” headertext=”操作” commandname=”cmdsave”>
<itemstyle font-size=”10pt”></itemstyle>
</asp:buttoncolumn>
<asp:templatecolumn>
<itemtemplate>
<input id=”button1″ style=”cursor: hand; width: 35px; color: blue; border-top-style: none; border-right-style: none; border-left-style: none; background-color: transparent; text-decoration: underline; border-bottom-style: none”
onclick=”editcell(this,1);” type=”button” value=”编辑” runat=”server”><input id=”button2″ style=”cursor: hand; display: none; color: blue; border-top-style: none; border-right-style: none; border-left-style: none; background-color: transparent; text-decoration: underline; border-bottom-style: none”
onclick=”editcell(this,2);” type=”button” value=”取消” runat=”server”>
</itemtemplate>
</asp:templatecolumn>
</columns>
<pagerstyle nextpagetext=”下一页” prevpagetext=”上一页”></pagerstyle>
</asp:datagrid>

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
<html>
<head>
<title> dstree </title>
<meta name=”author” content=”starsjz@hotmail.com” >
<style>
body,td{font:12px verdana}
#treebox{background-color:#fffffa;}
#treebox .ec{margin:0 5 0 5;}
#treebox .hasitems{font-weight:bold;height:20px;padding:3 6 0 6;margin:2px;cursor:hand;color:#555555;border:1px solid #fffffa;}
#treebox .items{height:20px;padding:3 6 0 6;margin:1px;cursor:hand;color:#555555;border:1px solid #fffffa;}
</style>
<base href=”http://vip.5d.cn/star/dstree/” />
<script>
//code by star 20003-4-7
var hc = “color:#990000;border:1px solid #cccccc”;
var sc = “background-color:#efefef;border:1px solid #cccccc;color:#000000;”;
var io = null;
function inittree(){
var rootn = document.all.menuxml.documentelement;
var sd = 0;
document.onselectstart = function(){return false;}
document.all.treebox.appendchild(createtree(rootn,sd));
}
function createtree(thisn,sd){
var nodeobj = document.createelement(“span”);
var upobj = document.createelement(“span”);
with(upobj){
style.marginleft = sd*10;
classname = thisn.haschildnodes()?”hasitems”:”items”;
innerhtml = “<img src=/Uploads/images1/202012/2816091194597549.gif class=ec>” + thisn.getattribute(“text”) +””;

onmousedown = function(){
if(event.button != 1) return;
if(this.getattribute(“cn”)){
this.setattribute(“open”,!this.getattribute(“open”));
this.cn.style.display = this.getattribute(“open”)?”inline”:”none”;
this.all.tags(“img”)[0].src = this.getattribute(“open”)?”/Uploads/images1/202012/2816091194597549.gif”:”/Uploads/images1/202012/2816091194597549.gif”;
}
if(io){
io.runtimestyle.csstext = “”;
io.setattribute(“selected”,false);
}
io = this;
this.setattribute(“selected”,true);
this.runtimestyle.csstext = sc;
}
onmouseover = function(){
if(this.getattribute(“selected”))return;
this.runtimestyle.csstext = hc;
}
onmouseout = function(){
if(this.getattribute(“selected”))return;
this.runtimestyle.csstext = “”;
}
oncontextmenu = contextmenuhandle;
onclick = clickhandle;
}

if(thisn.getattribute(“treeid”) != null){
upobj.setattribute(“treeid”,thisn.getattribute(“treeid”));
}
if(thisn.getattribute(“href”) != null){
upobj.setattribute(“href”,thisn.getattribute(“href”));
}
if(thisn.getattribute(“target”) != null){
upobj.setattribute(“target”,thisn.getattribute(“target”));
}

nodeobj.appendchild(upobj);
nodeobj.insertadjacenthtml(“beforeend”,”<br/>”)

if(thisn.haschildnodes()){
var i;
var nodes = thisn.childnodes;
var cn = document.createelement(“span”);
upobj.setattribute(“cn”,cn);
if(thisn.getattribute(“open”) != null){
upobj.setattribute(“open”,(thisn.getattribute(“open”)==”true”));
upobj.getattribute(“cn”).style.display = upobj.getattribute(“open”)?”inline”:”none”;
if( !upobj.getattribute(“open”))upobj.all.tags(“img”)[0].src =”/Uploads/images1/202012/2816091194597549.gif”;
}

for(i=0;i<nodes.length;cn.appendchild(createtree(nodes[i++],sd+1)));
nodeobj.appendchild(cn);
}
else{
upobj.all.tags(“img”)[0].src =”/Uploads/images1/202012/2816091194597549.gif”;
}
return nodeobj;
}
window.onload = inittree;
</script>

<script>
function clickhandle(){
// your code here
}
function contextmenuhandle(){
event.returnvalue = false;
var treeid = this.getattribute(“treeid”);
// your code here
}
</script>
</head>
<body>
<xml id=menuxml>
<?xml version=”1.0″ encoding=”gb2312″?>
<dstreeroot text=”根节点” open=”true” href=”http://” treeid=”123″>

<dstree text=”技术论坛” open=”false” treeid=””>
<dstree text=”5dmedia” open=”false” href=”http://” target=”box” treeid=”12″>
<dstree text=”网页编码” href=”http://” target=”box” treeid=”4353″ />
<dstree text=”手绘” href=”http://” target=”box” treeid=”543543″ />
<dstree text=”灌水” href=”http://” target=”box” treeid=”543543″ />
</dstree>
<dstree text=”blueidea” open=”false” href=”http://” target=”box” treeid=”213″>
<dstree text=”dreamweaver &amp; js” href=”http://” target=”box” treeid=”4353″ />
<dstree text=”flashactionscript” href=”http://” target=”box” treeid=”543543″ />
</dstree>
<dstree text=”csdn” open=”false” href=”http://” target=”box” treeid=”432″>
<dstree text=”js” href=”http://” target=”box” treeid=”4353″ />
<dstree text=”xml” href=”http://” target=”box” treeid=”543543″ />
</dstree>
</dstree>

<dstree text=”资源站点” open=”false” treeid=””>
<dstree text=”素材屋” href=”http://” target=”box” treeid=”12″ />
<dstree text=”桌面城市” open=”false” href=”http://” target=”box” treeid=”213″>
<dstree text=”壁纸” href=”http://” target=”box” treeid=”4353″ />
<dstree text=”字体” href=”http://” target=”box” treeid=”543543″ />
</dstree>
<dstree text=”msdn” open=”false” href=”http://” target=”box” treeid=”432″>
<dstree text=”dhtml” href=”http://” target=”box” treeid=”4353″ />
<dstree text=”htc” href=”http://” target=”box” treeid=”543543″ />
<dstree text=”xml” href=”” target=”box” treeid=”2312″ />
</dstree>
</dstree>

</dstreeroot>
</xml>
<table style=”position:absolute;left:100;top:100;”>
<tr><td id=treebox style=”width:400px;height:200px;border:1px solid #cccccc;padding:5 3 3 5;” valign=top></td></tr>
<tr><td style=”font:10px verdana;color:#999999″ align=right>by <font color=#660000>star</font><br/> 2003-4-8</td></tr>
</table>
</body>
</html>

针对javascript的几个对象的扩充函数
function checkbrowser()
{
this.ver=navigator.appversion
this.dom=document.getelementbyid?1:0
this.ie6=(this.ver.indexof(“msie 6”)>-1 && this.dom)?1:0;
this.ie5=(this.ver.indexof(“msie 5”)>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseint(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.mac=(this.ver.indexof(mac) > -1) ?1:0;
this.ope=(navigator.useragent.indexof(opera)>-1);
this.ie=(this.ie6 || this.ie5 || this.ie4)
this.ns=(this.ns4 || this.ns5)
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
this.nbw=(!this.bw)

return this;
}
/*
******************************************
日期函数扩充
******************************************
*/

/*
===========================================
//转换成大写日期(中文)
===========================================
*/
date.prototype.tocase = function()
{
var digits= new array(零,一,二,三,四,五,六,七,八,九,十,十一,十二);
var unit= new array(年,月,日,点,分,秒);

var year= this.getyear() + “”;
var index;
var output=””;

////////得到年
for (index=0;index<year.length;index++ )
{
output += digits[parseint(year.substr(index,1))];
}
output +=unit[0];

///////得到月
output +=digits[this.getmonth()] + unit[1];

///////得到日
switch (parseint(this.getdate() / 10))
{
case 0:
output +=digits[this.getdate() % 10];
break;
case 1:
output +=digits[10] + ((this.getdate() % 10)>0?digits[(this.getdate() % 10)]:””);
break;
case 2:
case 3:
output +=digits[parseint(this.getdate() / 10)] + digits[10]  + ((this.getdate() % 10)>0?digits[(this.getdate() % 10)]:””);
default:

break;
}
output +=unit[2];

///////得到时
switch (parseint(this.gethours() / 10))
{
case 0:
output +=digits[this.gethours() % 10];
break;
case 1:
output +=digits[10] + ((this.gethours() % 10)>0?digits[(this.gethours() % 10)]:””);
break;
case 2:
output +=digits[parseint(this.gethours() / 10)] + digits[10] + ((this.gethours() % 10)>0?digits[(this.gethours() % 10)]:””);
break;
}
output +=unit[3];

if(this.getminutes()==0&&this.getseconds()==0)
{
output +=”整”;
return output;
}

///////得到分
switch (parseint(this.getminutes() / 10))
{
case 0:
output +=digits[this.getminutes() % 10];
break;
case 1:
output +=digits[10] + ((this.getminutes() % 10)>0?digits[(this.getminutes() % 10)]:””);
break;
case 2:
case 3:
case 4:
case 5:
output +=digits[parseint(this.getminutes() / 10)] + digits[10] + ((this.getminutes() % 10)>0?digits[(this.getminutes() % 10)]:””);
break;
}
output +=unit[4];

if(this.getseconds()==0)
{
output +=”整”;
return output;
}

///////得到秒
switch (parseint(this.getseconds() / 10))
{
case 0:
output +=digits[this.getseconds() % 10];
break;
case 1:
output +=digits[10] + ((this.getseconds() % 10)>0?digits[(this.getseconds() % 10)]:””);
break;
case 2:
case 3:
case 4:
case 5:
output +=digits[parseint(this.getseconds() / 10)] + digits[10] + ((this.getseconds() % 10)>0?digits[(this.getseconds() % 10)]:””);
break;
}
output +=unit[5];

 

return output;
}

/*
===========================================
//转换成农历
===========================================
*/
date.prototype.tochinese = function()
{
//暂缺
}

/*
===========================================
//是否是闰年
===========================================
*/
date.prototype.isleapyear = function()
{
return (0==this.getyear()%4&&((this.getyear()%100!=0)||(this.getyear()%400==0)));
}

/*
===========================================
//获得该月的天数
===========================================
*/
date.prototype.getdaycountinmonth = function()
{
var mon = new array(12);

    mon[0] = 31; mon[1] = 28; mon[2] = 31; mon[3] = 30; mon[4]  = 31; mon[5]  = 30;
    mon[6] = 31; mon[7] = 31; mon[8] = 30; mon[9] = 31; mon[10] = 30; mon[11] = 31;

if(0==this.getyear()%4&&((this.getyear()%100!=0)||(this.getyear()%400==0))&&this.getmonth()==2)
{
return 29;
}
else
{
return mon[this.getmonth()];
}
}

/*
===========================================
//日期比较
===========================================
*/
date.prototype.compare = function(objdate)
{
if(typeof(objdate)!=”object” && objdate.constructor != date)
{
return -2;
}

var d = this.gettime() – objdate.gettime();

if(d>0)
{
return 1;
}
else if(d==0)
{
return 0;
}
else
{
return -1;
}
}

/*
===========================================
//格式化日期格式
===========================================
*/
date.prototype.format = function(formatstr)
{
var str = formatstr;

str=str.replace(/yyyy|yyyy/,this.getfullyear());
str=str.replace(/yy|yy/,(this.getyear() % 100)>9?(this.getyear() % 100).tostring():”0″ + (this.getyear() % 100));

str=str.replace(/mm/,this.getmonth()>9?this.getmonth().tostring():”0″ + this.getmonth());
str=str.replace(/m/g,this.getmonth());

str=str.replace(/dd|dd/,this.getdate()>9?this.getdate().tostring():”0″ + this.getdate());
str=str.replace(/d|d/g,this.getdate());

str=str.replace(/hh|hh/,this.gethours()>9?this.gethours().tostring():”0″ + this.gethours());
str=str.replace(/h|h/g,this.gethours());

str=str.replace(/mm/,this.getminutes()>9?this.getminutes().tostring():”0″ + this.getminutes());
str=str.replace(/m/g,this.getminutes());

str=str.replace(/ss|ss/,this.getseconds()>9?this.getseconds().tostring():”0″ + this.getseconds());
str=str.replace(/s|s/g,this.getseconds());

return str;
}

/*
===========================================
//由字符串直接实例日期对象
===========================================
*/
date.prototype.instancefromstring = function(str)
{
return new date(“2004-10-10”.replace(/-/g, “\/”));
}

/*
===========================================
//得到日期年月日等加数字后的日期
===========================================
*/
date.prototype.dateadd = function(interval,number)
{
var date = this;

    switch(interval)
    {
        case “y” :
            date.setfullyear(date.getfullyear()+number);
            return date;

        case “q” :
            date.setmonth(date.getmonth()+number*3);
            return date;

        case “m” :
            date.setmonth(date.getmonth()+number);
            return date;

        case “w” :
            date.setdate(date.getdate()+number*7);
            return date;
       
        case “d” :
            date.setdate(date.getdate()+number);
            return date;

        case “h” :
            date.sethours(date.gethours()+number);
            return date;

case “m” :
            date.setminutes(date.getminutes()+number);
            return date;

case “s” :
            date.setseconds(date.getseconds()+number);
            return date;

        default :
            date.setdate(d.getdate()+number);
            return date;
    }
}

/*
===========================================
//计算两日期相差的日期年月日等
===========================================
*/
date.prototype.datediff = function(interval,objdate)
{
//暂缺
}

/*
******************************************
数字函数扩充
******************************************
*/

/*
===========================================
//转换成中文大写数字
===========================================
*/
number.prototype.tochinese = function()
{
var num = this;
    if(!/^\d*(\.\d*)?$/.test(num)){alert(“number is wrong!”); return “number is wrong!”;}

    var aa = new array(“零”,”壹”,”贰”,”叁”,”肆”,”伍”,”陆”,”柒”,”捌”,”玖”);
    var bb = new array(“”,”拾”,”佰”,”仟”,”萬”,”億”,”点”,””);
   
    var a = (“”+ num).replace(/(^0*)/g, “”).split(“.”), k = 0, re = “”;

    for(var i=a[0].length-1; i>=0; i–)
    {
        switch(k)
        {
            case 0 : re = bb[7] + re; break;
            case 4 : if(!new regexp(“0{4}\\d{“+ (a[0].length-i-1) +”}$”).test(a[0]))
                     re = bb[4] + re; break;
            case 8 : re = bb[5] + re; bb[7] = bb[5]; k = 0; break;
        }
        if(k%4 == 2 && a[0].charat(i+2) != 0 && a[0].charat(i+1) == 0) re = aa[0] + re;
        if(a[0].charat(i) != 0) re = aa[a[0].charat(i)] + bb[k%4] + re; k++;
    }

    if(a.length>1) //加上小数部分(如果有小数部分)
    {
        re += bb[6];
        for(var i=0; i<a[1].length; i++) re += aa[a[1].charat(i)];
    }
    return re;

}

/*
===========================================
//保留小数点位数
===========================================
*/
number.prototype.tofixed=function(len)
{

if(isnan(len)||len==null)
{
len = 0;
}
else
{
if(len<0)
{
len = 0;
}
}

    return math.round(this * math.pow(10,len)) / math.pow(10,len);

}

/*
===========================================
//转换成大写金额
===========================================
*/
number.prototype.tomoney = function()
{
// constants:
var maximum_number = 99999999999.99;
// predefine the radix characters and currency symbols for output:
var cn_zero= “零”;
var cn_one= “壹”;
var cn_two= “贰”;
var cn_three= “叁”;
var cn_four= “肆”;
var cn_five= “伍”;
var cn_six= “陆”;
var cn_seven= “柒”;
var cn_eight= “捌”;
var cn_nine= “玖”;
var cn_ten= “拾”;
var cn_hundred= “佰”;
var cn_thousand = “仟”;
var cn_ten_thousand= “万”;
var cn_hundred_million= “亿”;
var cn_symbol= “”;
var cn_dollar= “元”;
var cn_ten_cent = “角”;
var cn_cent= “分”;
var cn_integer= “整”;
 
// variables:
var integral; // represent integral part of digit number.
var decimal; // represent decimal part of digit number.
var outputcharacters; // the output result.
var parts;
var digits, radices, bigradices, decimals;
var zerocount;
var i, p, d;
var quotient, modulus;
 
if (this > maximum_number)
{
return “”;
}
 
// process the coversion from currency digits to characters:
// separate integral and decimal parts before processing coversion:

 parts = (this + “”).split(“.”);
if (parts.length > 1)
{
integral = parts[0];
decimal = parts[1];
// cut down redundant decimal digits that are after the second.
decimal = decimal.substr(0, 2);
}
else
{
integral = parts[0];
decimal = “”;
}
// prepare the characters corresponding to the digits:
digits= new array(cn_zero, cn_one, cn_two, cn_three, cn_four, cn_five, cn_six, cn_seven, cn_eight, cn_nine);
radices= new array(“”, cn_ten, cn_hundred, cn_thousand);
bigradices= new array(“”, cn_ten_thousand, cn_hundred_million);
decimals= new array(cn_ten_cent, cn_cent);

 // start processing:
 outputcharacters = “”;
// process integral part if it is larger than 0:
if (number(integral) > 0)
{
zerocount = 0;
for (i = 0; i < integral.length; i++)
{
p = integral.length – i – 1;
d = integral.substr(i, 1);
quotient = p / 4;
modulus = p % 4;
if (d == “0”)
{
zerocount++;
}
else
{
if (zerocount > 0)
{
outputcharacters += digits[0];
}
zerocount = 0;
outputcharacters += digits[number(d)] + radices[modulus];
}

if (modulus == 0 && zerocount < 4)
{
outputcharacters += bigradices[quotient];
}
}

outputcharacters += cn_dollar;
}

// process decimal part if there is:
if (decimal != “”)
{
for (i = 0; i < decimal.length; i++)
{
d = decimal.substr(i, 1);
if (d != “0”)
{
outputcharacters += digits[number(d)] + decimals[i];
}
}
}

// confirm and return the final output string:
if (outputcharacters == “”)
{
outputcharacters = cn_zero + cn_dollar;
}
if (decimal == “”)
{
outputcharacters += cn_integer;
}

outputcharacters = cn_symbol + outputcharacters;
return outputcharacters;
}

number.prototype.toimage = function()
{
var num = array(
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0x5,0x5,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0x4,0x4,0x4,0x4,0x4}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0xf,0x1,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0xf,0x4,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0x5,0x5,0xf,0x4,0x4}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x1,0xf,0x4,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x1,0xf,0x5,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0x4,0x4,0x4}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0xf,0x5,0xf}”,
“#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0xf,0x4,0xf}”
);

var str = this + “”;
var iindex
var result=””
for(iindex=0;iindex<str.length;iindex++)
{
result +=”<img src=javascript:” & num(iindex) & “”>
}

return result;
}

/*
******************************************
其他函数扩充
******************************************
*/

/*
===========================================
//验证类函数
===========================================
*/
function isempty(obj)
{

    obj=document.getelementsbyname(obj).item(0);
    if(trim(obj.value)==””)
    {
     
        if(obj.disabled==false && obj.readonly==false)
        {
            obj.focus();
        }
return true;
    }
else
{
return false;
}
}

/*
===========================================
//无模式提示对话框
===========================================
*/
function modelessalert(msg)
{
   window.showmodelessdialog(“javascript:alert(\””+escape(msg)+”\”);window.close();”,””,”status:no;resizable:no;help:no;dialogheight:height:30px;dialogheight:40px;”);
}

 

/*
===========================================
//页面里回车到下一控件的焦点
===========================================
*/
function enter2tab()
{
var e = document.activeelement;
if(e.tagname == “input” &&
(
e.type == “text”     ||
e.type == “password” ||
e.type == “checkbox” ||
e.type == “radio”
)   ||
e.tagname == “select”)

{
if(window.event.keycode == 13)
{
    window.event.keycode = 9;
}
}
}
////////打开此功能请取消下行注释
//document.onkeydown = enter2tab;

function viewsource(url)
{
window.location = view-source:+ url;
}

///////禁止右键
document.oncontextmenu = function() { return false;}

 

/*
******************************************
字符串函数扩充
******************************************
*/

/*
===========================================
//去除左边的空格
===========================================

*/
string.prototype.ltrim = function()
{
return this.replace(/(^ *)/g, “”);
}

string.prototype.mid = function(start,len)
{
if(isnan(start)&&start<0)
{
return “”;
}

if(isnan(len)&&len<0)
{
return “”;
}

return this.substring(start,len);
}

/*
===========================================
//去除右边的空格
===========================================
*/
string.prototype.rtrim = function()
{
return this.replace(/( *$)/g, “”);
}

 

/*
===========================================
//去除前后空格
===========================================
*/
string.prototype.trim = function()
{
return this.replace(/(^ *)|( *$)/g, “”);
}

/*
===========================================
//得到左边的字符串
===========================================
*/
string.prototype.left = function(len)
{

if(isnan(len)||len==null)
{
len = this.length;
}
else
{
if(parseint(len)<0||parseint(len)>this.length)
{
len = this.length;
}
}

return this.substring(0,len);
}

/*
===========================================
//得到右边的字符串
===========================================
*/
string.prototype.right = function(len)
{

if(isnan(len)||len==null)
{
len = this.length;
}
else
{
if(parseint(len)<0||parseint(len)>this.length)
{
len = this.length;
}
}

return this.substring(this.length-len,this.length);
}

/*
===========================================
//得到中间的字符串,注意从0开始
===========================================
*/
string.prototype.mid = function(start,len)
{
if(isnan(start)||start==null)
{
start = 0;
}
else
{
if(parseint(start)<0)
{
start = 0;
}
}

if(isnan(len)||len==null)
{
len = this.length;
}
else
{
if(parseint(len)<0)
{
len = this.length;
}
}

return this.substring(start,start+len);
}

/*
===========================================
//在字符串里查找另一字符串:位置从0开始
===========================================
*/
string.prototype.instr = function(str)
{

if(str==null)
{
str = “”;
}

return this.indexof(str);
}

/*
===========================================
//在字符串里反向查找另一字符串:位置0开始
===========================================
*/
string.prototype.instrrev = function(str)
{

if(str==null)
{
str = “”;
}

return this.lastindexof(str);
}

 

/*
===========================================
//计算字符串打印长度
===========================================
*/
string.prototype.lengthw = function()
{
return this.replace(/[^\x00-\xff]/g,”**”).length;
}

/*
===========================================
//是否是正确的ip地址
===========================================
*/
string.prototype.isip = function()
{

var respacecheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;

if (respacecheck.test(this))
{
this.match(respacecheck);
if (regexp.$1 <= 255 && regexp.$1 >= 0
 && regexp.$2 <= 255 && regexp.$2 >= 0
 && regexp.$3 <= 255 && regexp.$3 >= 0
 && regexp.$4 <= 255 && regexp.$4 >= 0)
{
return true;    
}
else
{
return false;
}
}
else
{
return false;
}
  
}

 

/*
===========================================
//是否是正确的长日期
===========================================
*/
string.prototype.isdate = function()
{
var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
if(r==null)
{
return false;
}
var d = new date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getfullyear()==r[1]&&(d.getmonth()+1)==r[3]&&d.getdate()==r[4]&&d.gethours()==r[5]&&d.getminutes()==r[6]&&d.getseconds()==r[7]);

}

/*
===========================================
//是否是手机
===========================================
*/
string.prototype.ismobile = function()
{
return /^0{0,1}13[0-9]{9}$/.test(this);
}

/*
===========================================
//是否是邮件
===========================================
*/
string.prototype.isemail = function()
{
return /^\w+((-\w+)|(\.\w+))*\@[a-za-z0-9]+((\.|-)[a-za-z0-9]+)*\.[a-za-z0-9]+$/.test(this);
}

/*
===========================================
//是否是邮编(中国)
===========================================
*/

string.prototype.iszipcode = function()
{
return /^[\\d]{6}$/.test(this);
}

/*
===========================================
//是否是有汉字
===========================================
*/
string.prototype.existchinese = function()
{
//[\u4e00-\u9fa5]為漢字﹐[\ufe30-\uffa0]為全角符號
return /^[\x00-\xff]*$/.test(this);
}

/*
===========================================
//是否是合法的文件名/目录名
===========================================
*/
string.prototype.isfilename = function()
{
return !/[\\\/\*\?\|:”<>]/g.test(this);
}

/*
===========================================
//是否是有效链接
===========================================
*/
string.prototype.isurl = function()
{
return /^http:\/\/([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/.test(this);
}

/*
===========================================
//是否是有效的身份证(中国)
===========================================
*/
string.prototype.isidcard = function()
{
var isum=0;
var info=””;
var sid = this;

var acity={11:”北京”,12:”天津”,13:”河北”,14:”山西”,15:”内蒙古”,21:”辽宁”,22:”吉林”,23:”黑龙江”,31:”上海”,32:”江苏”,33:”浙江”,34:”安徽”,35:”福建”,36:”江西”,37:”山东”,41:”河南”,42:”湖北”,43:”湖南”,44:”广东”,45:”广西”,46:”海南”,50:”重庆”,51:”四川”,52:”贵州”,53:”云南”,54:”西藏”,61:”陕西”,62:”甘肃”,63:”青海”,64:”宁夏”,65:”新疆”,71:”台湾”,81:”香港”,82:”澳门”,91:”国外”};

if(!/^\d{17}(\d|x)$/i.test(sid))
{
return false;
}
sid=sid.replace(/x$/i,”a”);
//非法地区
if(acity[parseint(sid.substr(0,2))]==null)
{
return false;
}

var sbirthday=sid.substr(6,4)+”-“+number(sid.substr(10,2))+”-“+number(sid.substr(12,2));

var d=new date(sbirthday.replace(/-/g,”/”))

//非法生日
if(sbirthday!=(d.getfullyear()+”-“+ (d.getmonth()+1) + “-” + d.getdate()))
{
return false;
}
for(var i = 17;i>=0;i–)
{
isum += (math.pow(2,i) % 11) * parseint(sid.charat(17 – i),11);
}

if(isum%11!=1)
{
return false;
}
return true;

}

/*
===========================================
//是否是有效的电话号码(中国)
===========================================
*/
string.prototype.isphonecall = function()
{
return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);
}

/*
===========================================
//是否是数字
===========================================
*/
string.prototype.isnumeric = function(flag)
{
//验证是否是数字
if(isnan(this))
{

return false;
}

switch(flag)
{

case null://数字
case “”:
return true;
case “+”://正数
return/(^\+?|^\d?)\d*\.?\d+$/.test(this);
case “-“://负数
return/^-\d*\.?\d+$/.test(this);
case “i”://整数
return/(^-?|^\+?|\d)\d+$/.test(this);
case “+i”://正整数
return/(^\d+$)|(^\+?\d+$)/.test(this);
case “-i”://负整数
return/^[-]\d+$/.test(this);
case “f”://浮点数
return/(^-?|^\+?|^\d?)\d*\.\d+$/.test(this);
case “+f”://正浮点数
return/(^\+?|^\d?)\d*\.\d+$/.test(this);
case “-f”://负浮点数
return/^[-]\d*\.\d$/.test(this);
default://缺省
return true;
}
}

/*
===========================================
//转换成全角
===========================================
*/
string.prototype.tocase = function()
{
var tmp = “”;
for(var i=0;i<this.length;i++)
{
if(this.charcodeat(i)>0&&this.charcodeat(i)<255)
{
tmp += string.fromcharcode(this.charcodeat(i)+65248);
}
else
{
tmp += string.fromcharcode(this.charcodeat(i));
}
}
return tmp
}

/*
===========================================
//对字符串进行html编码
===========================================
*/
string.prototype.tohtmlencode = function
{
var str = this;

str=str.replace(“&”,”&amp;”);
str=str.replace(“<“,”&lt;”);
str=str.replace(“>”,”&gt;”);
str=str.replace(“”,”&apos;”);
str=str.replace(“\””,”&quot;”);

return str;
}

qqdao(青青岛)
 
 
  精心整理的输入判断js函数

关键词:字符串判断,字符串处理,字串判断,字串处理

//*********************************************************
// purpose: 判断输入是否为整数字
// inputs:   string
// returns:  true, false
//*********************************************************
function onlynumber(str)
{
    var i,strlength,tempchar;
    str=cstr(str);
   if(str==””) return false;
    strlength=str.length;
    for(i=0;i<strlength;i++)
    {
        tempchar=str.substring(i,i+1);
        if(!(tempchar==0||tempchar==1||tempchar==2||tempchar==3||tempchar==4||tempchar==5||tempchar==6||tempchar==7||tempchar==8||tempchar==9))
        {
        alert(“只能输入数字 ”);
        return false;
        }
    }
    return true;
}
//*********************************************************

//*********************************************************
// purpose: 判断输入是否为数值(包括小数点)
// inputs:   string
// returns:  true, false
//*********************************************************
function isfloat(str)
{ var tmp;
   var temp;
   var i;
   tmp =str;
if(str==””) return false; 
for(i=0;i<tmp.length;i++)
{temp=tmp.substring(i,i+1);
if((temp>=0&& temp<=9)||(temp==.)){} //check input in 0-9 and .
else   { return false;}
}
return true;
}

 

//*********************************************************
// purpose: 判断输入是否为电话号码
// inputs:   string
// returns:  true, false
//*********************************************************
function isphonenumber(str)
{
   var i,strlengh,tempchar;
   str=cstr(str);
   if(str==””) return false;
   strlength=str.length;
   for(i=0;i<strlength;i++)
   {
        tempchar=str.substring(i,i+1);
        if(!(tempchar==0||tempchar==1||tempchar==2||tempchar==3||tempchar==4||tempchar==5||tempchar==6||tempchar==7||tempchar==8||tempchar==9||tempchar==-))
        {
        alert(“电话号码只能输入数字和中划线 ”);
        return(false);
        }   
   }
   return(true);
}
//*********************************************************

//*********************************************************
// purpose: 判断输入是否为email
// inputs:   string
// returns:  true, false
//*********************************************************
function isemail(str)
{
    var bflag=true
       
    if (str.indexof(“”)!=-1) {
        bflag=false
    }
    if (str.indexof(“@”)==-1) {
        bflag=false
    }
    else if(str.charat(0)==”@”){
            bflag=false
    }
    return bflag
}

//*********************************************************
// purpose: 判断输入是否含有为中文
// inputs:   string
// returns:  true, false
//*********************************************************
function ischinese(str) 
{
if(escape(str).indexof(“%u”)!=-1)
  {
    return true;
  }
    return false;
}
//*********************************************************

//*********************************************************
// purpose: 判断输入是否含有空格
// inputs:   string
// returns:  true, false
//*********************************************************
function checkblank(str)
{
var strlength;
var k;
var ch;
strlength=str.length;
for(k=0;k<=strlength;k++)
  {
     ch=str.substring(k,k+1);
     if(ch==” “)
      {
      alert(“对不起 不能输入空格 ”); 
      return false;
      }
  }
return true;
}
//*********************************************************

 

                                       
//*********************************************************
// purpose: 去掉str两边空格
// inputs:   str
// returns:  去掉两边空格的str
//*********************************************************
function trim(str)
{
    var i,strlength,t,chartemp,returnstr;
    str=cstr(str);
    strlength=str.length;
    t=str;
    for(i=0;i<strlength;i++)
    {
        chartemp=str.substring(i,i+1);   
        if(chartemp==” “)
        {
            t=str.substring(i+1,strlength);
        }
        else
        {
               break;
        }
    }
    returnstr=t;
    strlength=t.length;
    for(i=strlength;i>=0;i–)
    {
        chartemp=t.substring(i,i-1);
        if(chartemp==” “)
        {
            returnstr=t.substring(i-1,0);
        }
        else
        {
            break;
        }
    }
    return (returnstr);
}

//*********************************************************

//*********************************************************
// purpose: 将数值类型转化为string
// inputs:   int
// returns:  string
//*********************************************************
function cstr(inp)
{
    return(“”+inp+””);
}
//*********************************************************

//*********************************************************
// purpose: 去除不合法字符,   ” < >
// inputs:   string
// returns:  string
//*********************************************************
function rep(str)
{var str1;
str1=str;
str1=replace(str1,””,”`”,1,0);
str1=replace(str1,”,”`”,1,0);
str1=replace(str1,”<“,”(“,1,0);
str1=replace(str1,”>”,”)”,1,0);
return str1;
}
//*********************************************************

//*********************************************************
// purpose: 替代字符
// inputs:   目标string,欲替代的字符,替代成为字符串,大小写是否敏感,是否整字代替
// returns:  string
//*********************************************************
function replace(target,oldterm,newterm,casesens,wordonly)
{ var wk ;
  var ind = 0;
  var next = 0;
  wk=cstr(target);
  if (!casesens)
   {
      oldterm = oldterm.tolowercase();   
      wk = target.tolowercase();
    }
  while ((ind = wk.indexof(oldterm,next)) >= 0)
  { 
         if (wordonly) 
              {
                  var before = ind – 1;    
                var after = ind + oldterm.length;
                  if (!(space(wk.charat(before)) && space(wk.charat(after))))
                    {
                      next = ind + oldterm.length;    
                       continue;     
                   }
          }
     target = target.substring(0,ind) + newterm + target.substring(ind+oldterm.length,target.length);
     wk = wk.substring(0,ind) + newterm + wk.substring(ind+oldterm.length,wk.length);
     next = ind + newterm.length;   
     if (next >= wk.length) { break; }
  }
  return target;
}
//*********************************************************
 

几个判断,并强制设置焦点:
//+————————————
// trim     去除字符串两端的空格
string.prototype.trim=function(){return this.replace(/(^ *)|( *$)/g,””)}
//————————————-

// avoiddeadlock 避免设置焦点死循环问题
// 起死原因:以文本框为例,当一个文本框的输入不符合条件时,这时,鼠标点击另一个文本框,触发第一个文本框的离开事件
//   ,产生设置焦点动作。现在产生了第二个文本框的离开事件,因此也要设置第二个文本框的焦点,造成死锁。
// 解决方案:设置一个全局对象[key],记录当前触发事件的对象,若其符合条件,则释放该key;若其仍不符合,则key还是指
//   向该对象,别的对象触发不到设置焦点的语句。
/////////////////////////////////////////
// 文本框控制函数
//
/////////////////////////////////////////
var g_obj = null;// 记住旧的控件
// hintflag参数:0表示没有被别的函数调用,因此出现提示;1表示被调用,不出现警告信息
// focusflag参数:指示是否要设置其焦点,分情况:0表示有的可为空;1表示有的不为空
// 避免死锁的公共部分
//+————————————
function textcom(obj, hintflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();
}
//————————————-
// 文本框不为空
//+————————————
function tbnotnull(obj, hintflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();

if (g_obj.value == “”)
{
if (hintflag == 0)
{
g_obj.focus();
alert(“内容不能为空!”);
}
return false;
}
else
g_obj = null;

return true;
}
//————————————-
// 输入内容为数字
//+————————————
function letnumber(obj, hintflag, focusflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();

if ((g_obj.value == “”) || isnan(g_obj.value))
{
if (hintflag == 0)
{

g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
alert(“输入的内容必须为数字!”);
}
return false;
}
else
g_obj = null;

return true;
}
//————————————-
// 输入内容为整数
//+————————————
function letinteger(obj, hintflag, focusflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();

if (!/^\d*$/.test(g_obj.value) || (g_obj.value == “”))
{
if (hintflag == 0)
{

g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
alert(“输入的内容必须为整数!”);
}
return false;
}
else
g_obj = null;

return true;
}
//————————————-
// 输入内容为字母
//+————————————
function letletter(obj, hintflag, focusflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}

if (!/^[a-za-z]*$/.test(g_obj.value))
{
if (hintflag == 0)
{
alert(“输入的内容必须为字母!”);
g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
}
return false;
}
else
{
g_obj = null;
}

return true;
}
//————————————-
// 内容大于某值
//+————————————
function letmorethan(obj, leftnumber, hintflag, focusflag)
{
var ifalert;// 是否出现警告
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}

g_obj.value = g_obj.value.trim();
if (g_obj.value == “”)
ifalert = 0;
else
ifalert = 1;

if ((g_obj.value == “”) || (isnan(g_obj.value)) || (g_obj.value < leftnumber))
{
if (hintflag == 0)
{
g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
// 更友好的提示
if (ifalert == 1)
{
if (leftnumber == 0)
alert(“内容必须为非负数!”);
else
alert(“输入的内容必须” + leftnumber + “以上!”);
}
}
return false;
}
else
g_obj = null;

return true;
}
//————————————-
// 内容大于某值,整数
//+————————————
function letmorethan_int(obj, leftnumber, hintflag, focusflag)
{
var ifalert;// 是否出现警告
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();
if (g_obj.value == “”)
ifalert = 0;
else
ifalert = 1;
if ((g_obj.value == “”) || (isnan(g_obj.value) || g_obj.value < leftnumber) || !/^\d*$/.test(g_obj.value))
{
if (hintflag == 0)
{
g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
{g_obj = null;}
if (ifalert == 1)// 当用户不输入的时候,不出现提示
{
// 更友好的提示
if (leftnumber == 0)
alert(“内容必须为非负整数!”);
else
alert(“且必须在” + leftnumber + “以上!”);
}
}
return false;
}
else
g_obj = null;

return true;
}
//————————————-
// 内容小于某值
//+————————————
function letlessthan(obj, rightnumber, hintflag, focusflag)
{
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();

if ((g_obj.value == “”) || (isnan(g_obj.value) || g_obj.value > rightnumber))
{
if (hintflag == 0)
{
g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
alert(“输入的内容必须在” + rightnumber + “以下!”);
}
return false;
}
else
{g_obj = null;}

return true;
}
//————————————-
// 内容介于两值中间
//+————————————
function letmid(obj, leftnumber, rightnumber, hintflag, focusflag)
{
var ifalert;// 是否出现警告
if (g_obj == null)
g_obj=event.srcelement;
else if ((g_obj != null) && (hintflag == 0) && (g_obj != obj))
{
g_obj = null;
return;
}
g_obj.value = g_obj.value.trim();
if (g_obj.value == “”)
ifalert = 0;
else
ifalert = 1;
// 首先应该为数字
if (letnumber(g_obj, 1))
{
if (!(letmorethan(obj,leftnumber,1,0) && letlessthan(obj,rightnumber,1,0)))
{
if (hintflag == 0)
{
g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
if (ifalert == 1)// 当用户不输入的时候,不出现提示
alert(“输入的内容必须介于” + leftnumber + “和” + rightnumber + “之间!”);
}

return false;
}
else
{g_obj = null;}
}
else
{
if (hintflag == 0)
{

g_obj.value = “”;
if (focusflag == 1)
g_obj.focus();
else
g_obj = null;
if (ifalert == 1)
alert(“输入的内容必须为数字!\n” +
“且介于” + leftnumber + “和” + rightnumber + “之间!”);
}

return false;
}

return true;
}
//————————————-
/////////////////////////////////////////
// 下拉框
/////////////////////////////////////////
// 下拉框,务必选择
//+————————————
function onsellostfocus(obj)
{
if (g_obj == null)
{
g_obj=event.srcelement;
}
else if ((g_obj!=null) && (g_obj!=obj))
{
g_obj = null;
return;
}

if (g_obj.selectedindex == 0)
{
g_obj.focus();
}
else
{
g_obj = null;
}
}

/*
    随风javascript函数库
  请把经过测试的函数加入库
*/

/********************
函数名称:strlenthbybyte
函数功能:计算字符串的字节长度,即英文算一个,中文算两个字节
函数参数:str,为需要计算长度的字符串
********************/
function strlenthbybyte(str)
{
var len;
var i;
len = 0;
for (i=0;i<str.length;i++)
{
if (str.charcodeat(i)>255) len+=2; else len++;
}
return len;
}

/********************
函数名称:isemailaddress
函数功能:检查email邮件地址的合法性,合法返回true,反之,返回false
函数参数:obj,需要检查的email邮件地址
********************/
function isemailaddress(obj)
{
var pattern=/^[a-za-z0-9\-]+@[a-za-z0-9\-\.]+\.([a-za-z]{2,3})$/;
if(pattern.test(obj))
{
return true;
}
else
{
return false;
}
}

/********************
函数名称:popwindow
函数功能:弹出新窗口
函数参数:pageurl,新窗口地址;winwidth,窗口的宽;winheight,窗口的高
********************/
function popwindow(pageurl,winwidth,winheight)
{
var popwin=window.open(pageurl,”popwin”,”scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width=”+winwidth+”,height=”+winheight);
return false;
}

/********************
函数名称:popremotewindow
函数功能:弹出可以控制父窗体的原程窗口
函数参数:pageurl,新窗口地址;
调用方法:打开窗口:<a href=”javascript:popremotewindow(url);”>open</a>
          控制父窗体:opener.location=url;当然还可以有其他的控制
********************/
function popremotewindow(pageurl)
{
var remote=window.open(url,”remotewindow”,”scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes”);
if(remote.opener==null)
{
remote.opener=window;
}
}

/********************
函数名称:istelephone
函数功能:固话,手机号码检查函数,合法返回true,反之,返回false
函数参数:obj,待检查的号码
检查规则:
  (1)电话号码由数字、”(“、”)”和”-“构成
  (2)电话号码为3到8位
  (3)如果电话号码中包含有区号,那么区号为三位或四位
  (4)区号用”(“、”)”或”-“和其他部分隔开
  (5)移动电话号码为11或12位,如果为12位,那么第一位为0
  (6)11位移动电话号码的第一位和第二位为”13″
  (7)12位移动电话号码的第二位和第三位为”13″
********************/
function istelephone(obj)
{
var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
if(pattern.test(obj))
{
return true;
}
else
{
return false;
}
}

/********************
函数名称:islegality
函数功能:检查字符串的合法性,即是否包含” 字符,包含则返回false;反之返回true
函数参数:obj,需要检测的字符串
********************/
function islegality(obj)
{
var intcount1=obj.indexof(“\””,0);
var intcount2=obj.indexof(“\”,0);
if(intcount1>0 || intcount2>0)
{
return false;
}
else
{
return true;
}
}

/********************
函数名称:isnumber
函数功能:检测字符串是否全为数字
函数参数:str,需要检测的字符串
********************/
function isnumber(str)
{
var number_chars = “1234567890”;
var i;
for (i=0;i<str.length;i++)
{
if (number_chars.indexof(str.charat(i))==-1) return false;
}
return true;
}

/********************
函数名称:trim
函数功能:去除字符串两边的空格
函数参数:str,需要处理的字符串
********************/
function trim(str)
{
return str.replace(/(^ *)|( *$)/g, “”);
}

/********************
函数名称:ltrim
函数功能:去除左边的空格
函数参数:str,需要处理的字符串
********************/
function ltrim(str)
{
return str.replace(/(^ *)/g, “”);
}

/********************
函数名称:rtrim
函数功能:去除右边的空格
函数参数:str,需要处理的字符串
********************/
function rtrim(str)
{
 return this.replace(/( *$)/g, “”);
}

/********************
函数名称:isnull
函数功能:判断给定字符串是否为空
函数参数:str,需要处理的字符串
********************/
function isnull(str)
{
if(trim(str)==””)
{
return false;
}
else
{
return true;
}
}

/********************
函数名称:cookieenabled
函数功能:判断cookie是否开启
********************/
function cookieenabled()
{
return (navigator.cookieenabled)? true : false;
}

/*字符串替换方法*/
function strreplace(srcstring,findstring,replacestring,start)
{
//code
}

/*客户端html编码*/
function htmlencode(str)
{
//code
}

/********************************************************************
**
*函数功能:判断是否是闰年*
*输入参数:数字字符串*
*返回值:true,是闰年/false,其它*
*调用函数:*
**
********************************************************************/
function isleapyear(iyear)
{
if (iyear+”” == “undefined” || iyear+””== “null” || iyear+”” == “”)
return false;

iyear = parseint(iyear);
varisvalid= false;

if((iyear % 4 == 0 && iyear % 100 != 0) || iyear % 400 == 0)
isvalid= true;

return isvalid;  
}
/********************************************************************
**
*函数功能:取出指定年、月的最后一天*
*输入参数:年份,月份*
*返回值:某年某月的最后一天*
*调用函数:isleapyear*
**
********************************************************************/
function getlastday(iyear,imonth)
{
iyear = parseint(iyear);
imonth = parseint(imonth);

variday = 31;

if((imonth==4||imonth==6||imonth==9||imonth==11)&&iday == 31)
iday = 30;

if(imonth==2 )
if (isleapyear(iyear))
iday = 29;
else
iday = 28;
 return iday;  
}
/********************************************************************
**
*函数功能:去字符串的头空和尾空*
*输入参数:字符串*
*返回值:字符串/null如果输入字符串不正确*
*调用函数:trimleft() 和 trimright()*
**
********************************************************************/
function trim( str )
{
varresultstr =””;

resultstr =trimleft(str);
resultstr =trimright(resultstr);

return resultstr;
}

/********************************************************************
**
*函数功能:去字符串的头空*
*输入参数:字符串*
*返回值:字符串/null如果输入字符串不正确*
*调用函数:*
**
********************************************************************/
function trimleft( str )
{
varresultstr =””;
vari =len= 0;

if (str+”” == “undefined” || str ==null)
return null;

str+= “”;

if (str.length == 0)
resultstr =””;
else
{
len= str.length;

while ((i <= len) && (str.charat(i)== ” “))
i++;

resultstr =str.substring(i, len);
}

return resultstr;
}

/********************************************************************
**
*函数功能:去字符串的尾空*
*输入参数:字符串*
*返回值:字符串/null如果输入字符串不正确*
*调用函数:*
**
********************************************************************/
function trimright(str)
{
varresultstr =””;
vari =0;

if (str+”” == “undefined” || str ==null)
return null;

str+= “”;

if (str.length == 0)
resultstr =””;
else
{
i =str.length – 1;
while ((i >= 0)&& (str.charat(i) == ” “))
i–;

resultstr =str.substring(0, i + 1);
}

return resultstr;
}

/********************************************************************
**
*函数功能:判断输入的字符串是否为数字*
*输入参数:输入的对象*
*返回值:true-数字/false-非数字*
*调用函数:*
**
********************************************************************/
function isnumber(objname)
{
var strnumber = objname.value;
var intnumber;

if(trim(strnumber) == “”)
{
return true;
}

intnumber = parseint(strnumber, 10);
if (isnan(intnumber))
{
alert(“请输入数字.”);
objname.focus();
return false;
}
return true;
}

/********************************************************************
**
*函数功能:判断输入的字符串是否为数字*
*输入参数:输入的对象*
*返回值:true-数字/false-非数字*
*调用函数:*
**
********************************************************************/
function isfloat(objname)
{
var strfloat = objname.value;
var intfloat;

if(trim(strfloat) == “”)
{
return true;
}

intfloat = parsefloat(strfloat);
if (isnan(intfloat))
{
alert(“please input a number.”);
objname.focus();
return false;
}
return true;
}

}

/********************************************************************
**
*函数功能:判断输入的字符串是否为合法的时间*
*输入参数:输入的字符串*
*返回值:true-合法的时间/false-非法的时间*
*调用函数:*
**
********************************************************************/
function checkdate(strdate)
{
var strdatearray;
var strday;
var strmonth;
var stryear;
var intday;
var intmonth;
var intyear;
var strseparator = “-“;
var err = 0;

strdatearray = strdate.split(strseparator);

if (strdatearray.length != 3)
{
err = 1;
return false;
}
else
{
stryear = strdatearray[0];
strmonth = strdatearray[1];
strday = strdatearray[2];
}

intday = parseint(strday, 10);
if (isnan(intday))
{
err = 2;
return false;
}
intmonth = parseint(strmonth, 10);
if (isnan(intmonth))
{
        err = 3;
return false;
}
intyear = parseint(stryear, 10);
if(stryear.length != 4)
{
return false;
}
if (isnan(intyear))
{
err = 4;
return false;
}

if (intmonth>12 || intmonth<1)
{
err = 5;
return false;
}

if ((intmonth == 1 || intmonth == 3 || intmonth == 5 || intmonth == 7 || intmonth == 8 || intmonth == 10 || intmonth == 12) && (intday > 31 || intday < 1))
{
err = 6;
return false;
}

if ((intmonth == 4 || intmonth == 6 || intmonth == 9 || intmonth == 11) && (intday > 30 || intday < 1))
{
err = 7;
return false;
}

if (intmonth == 2)
{
if (intday < 1)
{
err = 8;
return false;
}

if (leapyear(intyear) == true)
{
if (intday > 29)
{
err = 9;
return false;
}
}
else
{
if (intday > 28)
{
err = 10;
return false;
}
}
}

return true;
}

/********************************************************************
**
*函数功能:判断是否为闰年*
*输入参数:输入的年*
*返回值:true-是/false-不是*
*调用函数:*
**
********************************************************************/
function leapyear(intyear)
{
if (intyear % 100 == 0)
{
if (intyear % 400 == 0) { return true; }
}
else
{
if ((intyear % 4) == 0) { return true; }
}
return false;
}

/********************************************************************
*函数功能:*
********************************************************************/
function formdatecheck(year,month,day)
{
var stry = trim(year);
var strm = trim(month);
var strd = trim(day);
var strdate = stry + “-” + strm + “-” + strd;
if((stry + strm + strd) != “”)
{
if(!checkdate(strdate))
{
return false;
}
}
return true;
}

/********************************************************************
*函数功能:将form所有输入字段重置*
********************************************************************/
function setformreset(objform)
{
objform.reset();
}
/********************************************************************
*函数功能:计算字符串的实际长度*
********************************************************************/

function strlen(str)
{
var len;
var i;
len = 0;
for (i=0;i<str.length;i++)
{
if (str.charcodeat(i)>255) len+=2; else len++;
}
return len;
}
/********************************************************************
*函数功能:判断输入的字符串是不是中文*
********************************************************************/

function ischarsinbag (s, bag)
{
var i,c;
for (i = 0; i < s.length; i++)
{
c = s.charat(i);//字符串s中的字符
if (bag.indexof(c) > -1)
return c;
}
return “”;
}

function ischinese(s)
{
var errorchar;
var badchar = “abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789><,[]{}?/+=|\\”:;~!#$%()`”;
errorchar = ischarsinbag( s, badchar)
if (errorchar != “” )
{
//alert(“请重新输入中文\n”);
return false;
}

return true;
}

/********************************************************************
*函数功能:判断输入的字符串是不是英文*
********************************************************************/

function ischarsinbagen (s, bag)
{
var i,c;
for (i = 0; i < s.length; i++)
{
c = s.charat(i);//字符串s中的字符
if (bag.indexof(c) <0)
return c;
}
return “”;
}

function isenglish(s)
{
var errorchar;
var badchar = ” abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz”;
errorchar = ischarsinbagen( s, badchar)
if (errorchar != “” )
{
//alert(“请重新输入英文\n”);
return false;
}

return true;
}
function isnum(s)
{
var errorchar;
var badchar = “0123456789”;
errorchar = ischarsinbagen( s, badchar)
if (errorchar != “” )
{
//alert(“请重新输入英文\n”);
return false;
}

return true;

自动显示txt文本的内容
把如下代码加入<body>区域中
 <script language=vbscript>
function bytes2bstr(vin)
    strreturn = “”
    for i = 1 to lenb(vin)
        thischarcode = ascb(midb(vin,i,1))
        if thischarcode < &h80 then
            strreturn = strreturn & chr(thischarcode)
        else
            nextcharcode = ascb(midb(vin,i+1,1))
            strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
            i = i + 1
        end if
    next
    bytes2bstr = strreturn
end function
</script>
<script language=”javascript”>
var xmlurl = new activexobject(microsoft.xmlhttp);
xmlurl.open(get,1.txt);
xmlurl.send();
settimeout(alert(bytes2bstr(xmlurl.responsebody)),2000);
</script>

 

我也来帖几个:
//detect client browse version
function testnavigator(){
var message=”系统检测到你的浏览器的版本比较低,建议你使用ie5.5以上的浏览器,否则有的功能可能不能正常使用.你可以到http://www.microsoft.com/china/免费获得ie的最新版本!”;
var ua=navigator.useragent;
var ie=false;
if(navigator.appname==”microsoft internet explorer”)
{
ie=true;
}
if(!ie){
alert(message);
return;
}
var ieversion=parsefloat(ua.substring(ua.indexof(“msie “)+5,ua.indexof(“;”,ua.indexof(“msie “))));
if(ieversion< 5.5){
alert(message);
return;
}
}

//detect client browse version
function testnavigator(){
var message=”系统检测到你的浏览器的版本比较低,建议你使用ie5.5以上的浏览器,否则有的功能可能不能正常使用.你可以到http://www.microsoft.com/china/免费获得ie的最新版本!”;
var ua=navigator.useragent;
var ie=false;
if(navigator.appname==”microsoft internet explorer”)
{
ie=true;
}
if(!ie){
alert(message);
return;
}
var ieversion=parsefloat(ua.substring(ua.indexof(“msie “)+5,ua.indexof(“;”,ua.indexof(“msie “))));
if(ieversion< 5.5){
alert(message);
return;
}
}

//ensure current window is the top window
function checktopwindow(){
if(window.top!=window && window.top!=null){
window.top.location=window.location;
}
}

//force close window
function closewindow()
{
var ua=navigator.useragent;
var ie=navigator.appname==”microsoft internet explorer”?true:false;
if(ie)
{
var ieversion=parsefloat(ua.substring(ua.indexof(“msie “)+5,ua.indexof(“;”,ua.indexof(“msie “))));
if(ieversion< 5.5)
{
var str  = <object id=notipclose classid=”clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11″>
str += <param name=”command” value=”close”></object>;
document.body.insertadjacenthtml(“beforeend”, str);
try
{
document.all.notipclose.click();
}
catch(e){}
}
else
{
window.opener =null;
window.close();
}
}
else
{
window.close()
}
}

//tirm string
function trim(s)
{
 return s.replace( /^ */, “” ).replace( / *$/, “” );
}

//uri encode
function encode(content){
return encodeuri(content);
}

//uri decode
function decode(content){
return decodeuri(content);
}

这些都我的原创.
打开calendar选择,可以限制是否可选择当前日期后的日期.
//open a calendar window.
function opencalender(ctlvalue){
var url=”/twms/component/calendar.html”;
var param=”dialogheight:200px;dialogwidth:400px;center:yes;status:no;help:no;scroll:yes;resizable:yes;”;
var result=window.showmodaldialog(url,ctlvalue.value,param);
if(result!=null && result!=”” && result!=”undefined”){
ctlvalue=result;
}
}

calendar.html
<html>
<head>
<title>选择日期:</title>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″>
 <link href=”/twms/css/common.css” type=”text/css” rel=”stylesheet”>
<script language=”javascript”>
var limit=true;

function runnian(the_year)
{
if ((the_year%400==0) || ((the_year%4==0) && (the_year%100!=0)))
return true;
else
return false;
}

function getweekday(the_year,the_month)
{
 
var allday=0;
if (the_year>2000)
{
 
for (i=2000 ;i<the_year; i++)
{
if (runnian(i))
allday += 366;
else
allday += 365;
}

for (i=2; i<=the_month; i++)
{
switch (i)
{
case 2 :
if (runnian(the_year))
allday += 29;
else
allday += 28;
break;
case 3 : allday += 31; break;
case 4 : allday += 30; break;
case 5 : allday += 31; break;
case 6 : allday += 30; break;
case 7 : allday += 31; break;
case 8 : allday += 31; break;
case 9 : allday += 30; break;
case 10 : allday += 31; break;
case 11 : allday += 30; break;
case 12 :  allday += 31; break;
   
}
}
}
 
switch (the_month)
{
case 1:return(allday+6)%7;

case 2 :
if (runnian(the_year))
return (allday+1)%7;
else
return (allday+2)%7;

case 3:return(allday+6)%7;
case 4:return (allday+7)%7;
case 5:return(allday+6)%7;
case 6:return (allday+7)%7;
case 7:return(allday+6)%7;
case 8:return(allday+6)%7;
case 9:return (allday+7)%7;
case 10:return(allday+6)%7;
case 11:return (allday+7)%7;
case 12:return(allday+6)%7;

}
}

function chooseday(the_year,the_month,the_day)
{
var firstday;
firstday = getweekday(the_year,the_month);
showcalender(the_year,the_month,the_day,firstday);
}

function nextmonth(the_year,the_month)
{
if (the_month==12)
chooseday(the_year+1,1,0);
else
chooseday(the_year,the_month+1,0);
}

function prevmonth(the_year,the_month)
{
if (the_month==1)
chooseday(the_year-1,12,0);
else
chooseday(the_year,the_month-1,0);
}

function prevyear(the_year,the_month)
{
chooseday(the_year-1,the_month,0);
}

function nextyear(the_year,the_month)
{
chooseday(the_year+1,the_month,0);
}

function showcalender(the_year,the_month,the_day,firstday)
{
var month_day;
var showmonth;
var today= new date();
//alert(today.getmonth());
 
switch (the_month)
{
case 1 : showmonth = “一月”; month_day = 31; break;
case 2 :
showmonth = “二月”;
if (runnian(the_year))
month_day = 29;
else
month_day = 28;
break;
case 3 : showmonth = “三月”; month_day = 31; break;
case 4 : showmonth = “四月”; month_day = 30; break;
case 5 : showmonth = “五月”; month_day = 31; break;
case 6 : showmonth = “六月”; month_day = 30; break;
case 7 : showmonth = “七月”; month_day = 31; break;
case 8 : showmonth = “八月”; month_day = 31; break;
case 9 : showmonth = “九月”; month_day = 30; break;
case 10 : showmonth = “十月”; month_day = 31; break;
case 11 : showmonth = “十一月”; month_day = 30; break;
case 12 : showmonth = “十二月”; month_day = 31; break;
}
 
var tabletagbegin=”<table cellpadding=0 cellspacing=0 border=1 bordercolor=#999999 width=95% align=center valign=top>”;
var blanknexttd=”<td width=0>&gt;&gt;</td>”;
var blankprevtd=”<td width=0>&lt;&lt;</td>”;
var blankdaytd=”<td align=center bgcolor=#cccccc>&nbsp;</td>”;
var nextyeartd=”<td width=0 onclick=nextyear(“+the_year+”,”+the_month+”)  style=cursor:hand>&gt;&gt;</td>”;
var prevyeartd=”<td width=0 onclick=prevyear(“+the_year+”,”+the_month+”)  style=cursor:hand>&lt;&lt;</td>”;
var nextmonthtd=”<td width=0 onclick=nextmonth(“+the_year+”,”+the_month+”)  style=cursor:hand>&gt;&gt;</td>”;
var prevmonthtd=”<td width=0 onclick=prevmonth(“+the_year+”,”+the_month+”)  style=cursor:hand>&lt;&lt;</td>”;
var valuetdtagbegin=”<td width=100 align=center colspan=5>”;

var weektexttr=”<tr align=center bgcolor=#999999>”;
weektexttr+=”<td><strong><font color=#0000cc>日</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>一</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>二</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>三</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>四</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>五</font></strong>”;
weektexttr+=”<td><strong><font color=#0000cc>六</font></strong>”;
weektexttr+=”</tr>”;

var text=tabletagbegin;

text+=”<tr>”+prevyeartd+valuetdtagbegin+the_year+”</td>”;
if(limit && (the_year>=today.getyear()) ){
text+=blanknexttd;
}
else{
text+=nextyeartd;
}
text+=”</tr>”;

text+=”<tr>”+prevmonthtd+valuetdtagbegin+the_month+”</td>”;
if(limit && (the_year>=today.getyear()) && (the_month>=(today.getmonth()+1)) ){
text+=blanknexttd;
}
else{
text+=nextmonthtd;
}
text+=”</tr>”+weektexttr;

text+=”<tr>”;

for (var i=1; i<=firstday; i++){
text+=blankdaytd;
}

for (var i=1; i<=month_day; i++)
{
var bgcolor=””;
if ( (the_year==today.getyear()) && (the_month==today.getmonth()+1) && (i==today.getdate()) )
{
bgcolor = “#ffcccc”;
}
else
{
bgcolor = “#cccccc”;
}

if (the_day==i)
{
bgcolor = “#ffffcc”;
}

if(limit && (the_year>=today.getyear()) && (the_month>=(today.getmonth()+1)) && (i>today.getdate()))
{
text+=”<td align=center bgcolor=#cccccc >” + i + “</td>”;
}
else
{
text+=”<td align=center bgcolor=” + bgcolor + ” style=cursor:hand onclick=getselectedday(” + the_year + “,” + the_month + “,” + i + “)>” + i + “</td>”;
}

firstday = (firstday + 1)%7;
if ((firstday==0) && (i!=month_day)) {
text += “</tr><tr>”;
}
}

if (firstday!=0)
{
for (var i=firstday; i<7; i++)
{
text+=blankdaytd;
}

text+= “</tr>”;
}
 
text += “</table>”;
document.all.divcontainer.innerhtml=text;
}

function getselectedday(the_year,the_month,the_day){
window.returnvalue=the_year + “-” + format(the_month) + “-” + format(the_day);
//alert(window.returnvalue);
window.close();
}

function format(i){
if(i<10){
return “0”+i;
}
else{
return i;
}
}

function init(){
var args=window.dialogarguments.split(“-“);
//alert(args);
var year=parseint(args[0]);
var month=parseint(args[1]);
var day=parseint(args[2]);
var firstday=getweekday(year,month);
showcalender(year,month,day,firstday);
}
</script>
</head>
<body style=”text-align:center”>
<div id=”divcontainer”/>
<script language=javascript>
init();
</script>
</body>
</html>

//parse the search string,then return a object.
//object info:
//–property:
//—-result:a array contained a group of name/value item.the item is nested class.
//–method:
//—-getnameditem(name):find item by name.if not exists,return null;
//—-appenditem(name,value):apppend an item into result tail;
//—-removetitem(name):remove item which contained in result and named that name.
//—-tostring():override object.tostring();return a regular query string.
function parsequerystring(search){
var object=new object();
object.getnameditem=getnameditem;
object.appenditem=appenditem;
object.removeitem=removeitem;
object.tostring=tostring;
object.result=new array();

function parseitem(itemstr){
var arstr=itemstr.split(“=”);
var obj=new object();
obj.name=arstr[0];
obj.value=arstr[1];
obj.tostring=tostring;
function tostring(){
return obj.name+”=”+obj.value;
}
return obj;
}

function appenditem(name,value){
var obj=parseitem(name+”=”+value);
object.result[object.result.length]=obj;
}

function removeitem(name){
var j;
for(j=0;j<object.result.length;j++){
if(object.result[j].name==name){
object.result.replice(j,1);
}
}
}

function getnameditem(name){
var j;
for(j=0;j<object.result.length;j++){
if(object.result[j].name==name){
return object.result[j];
}
}

return null;
}

function tostring(){
var k;
var str=””;
for(k=0;k<object.result.length;k++){
str+=object.result[k].tostring()+”&”;
}

return str.substring(0,str.length-1);
}

var items=search.split(“&”);
var i;
for(i=0;i<items.length;i++){
object.result[i]=parseitem(items[i]);
}

return object;
}

关闭窗体[无须修改][共1步]

====1、将以下代码加入heml的<body></body>之间:

<script language=”javascript”>
function shutwin(){
window.close();
return;}
</script>
<a href=”javascript:shutwin();”>关闭本窗口</a>

检测系统信息

<script language=”javascript” type=”text/javascript”>
<!–
var newline = “\r\r”
var now = new date()
var millinow=now.gettime()/1000
var hours = now.gethours()
var minutes = now.getminutes()
var seconds = now.getseconds()
var yourlocation=””
now.sethours(now.gethours()+1)
var min=60*now.getutchours()+now.getutcminutes() + now.getutcseconds()/60;
var internettime=(min/1.44)
internettime=”internet time: @”+math.floor(internettime)
var clock = “its exactly “+hours+”:”+minutes+”:”+seconds+” hours” 
var browser = “you are using ” + navigator.appname +” “+navigator.appversion
yourlocation=”you are probably living in “+yourlocation
var winwidth= window.screen.width
var winheight= window.screen.height
var screenresolution= “screen resolution: “+window.screen.width+” x “+window.screen.height
var lastdoc = “you came from: “+document.referrer
var expdays = 30;
var exp = new date();
exp.settime(exp.gettime() + (expdays*24*60*60*1000));
function who(info){
var visitorname = getcookie(visitorname)
if (visitorname == null) {
visitorname = “stranger”;
setcookie (visitorname, visitorname, exp);
}
return visitorname;
}
function when(info){
// when
var rightnow = new date()
var wwhtime = 0;
wwhtime = getcookie(wwhenh)
wwhtime = wwhtime * 1
var lasthereformatting = new date(wwhtime);  // date-i-fy that number
var intlastvisit = (lasthereformatting.getyear() * 10000)+(lasthereformatting.getmonth() * 100) +
lasthereformatting.getdate()
var lasthereindateformat = “” + lasthereformatting;  // gotta use substring functions
var dayofweek = lasthereindateformat.substring(0,3)
var datemonth = lasthereindateformat.substring(4,11)
var timeofday = lasthereindateformat.substring(11,16)
var year = lasthereindateformat.substring(23,25)
var wwhtext = dayofweek + “, ” + datemonth + ” at ” + timeofday // display
setcookie (“wwhenh”, rightnow.gettime(), exp)
return wwhtext;
}
function count(info){
var psj=0;
// how many times
var wwhcount = getcookie(wwhcount)
if (wwhcount == null) {
wwhcount = 0;
}
else{
wwhcount++;
}
setcookie (wwhcount, wwhcount, exp);
return wwhcount;
}
function set(){
visitorname = prompt(“who are you?”);
setcookie (visitorname, visitorname, exp);
setcookie (wwhcount, 0, exp);
setcookie (wwhenh, 0, exp);
}
function getcookieval (offset) { 
var endstr = document.cookie.indexof (“;”, offset); 
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function getcookie (name) {
var arg = name + “=”; 
var alen = arg.length;
var clen = document.cookie.length; 
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getcookieval (j);
i = document.cookie.indexof(” “, i) + 1;
if (i == 0) break;
}
return null;
}
function setcookie (name, value) {
var argv = setcookie.arguments;
var argc = setcookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + “=” + escape (value) +
((expires == null) ? “” : (“; expires=” + expires.togmtstring())) +
((path == null) ? “” : (“; path=” + path)) + 
((domain == null) ? “” : (“; domain=” + domain)) +
((secure == true) ? “; secure” : “”);
}
function deletecookie (name) {
var exp = new date(); 
exp.settime (exp.gettime() – 1); 
// this cookie is history
var cval = getcookie (name); 
document.cookie = name + “=” + cval + “; expires=” + exp.togmtstring();
}
var countvisits=”youve been here ” + count() + ” time(s). last time was ” + when() +”.”
if (navigator.javaenabled()) {
var javaenabled=”your browser is able to run java-applets”;
}
else {
var javaenabled=”your browser is not able to run java-applets”;
}
function showalert() {
var later = new date()
var millilater=later.gettime()/1000
var loadtime=(math.floor((millilater-millinow)*100))/100
var loadtimeresult= “it took you “+loadtime+” seconds to load this page”
var babiesborn=math.ceil(loadtime*4.18)
var babiesbornresult=”while this page was loading “+babiesborn+” babies have been born”
if (babiesborn==1){babiesbornresult=”while this page was loading “+babiesborn+” baby has been born”}
alert
(newline+newline+browser+newline+clock+newline+loadtimeresult+newline+internettime+newline+screenresolution+newline+lastdoc+newline+countvisits+newline+javaenabled+newline+babiesbornresult+newline+newline)
}
// –></script>
<body onload=”showalert()”>

密码保护:

将以下代码加入heml的<body></body>之间:



六年
建站经验

多一份参考,总有益处

联系万讯互动,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

咨询热线:18692386458