2024年1月27日发(作者:)

javascript 常用代码大全-网页设计,HTMLCSS
//打开模式对话框
function doselectuser(txtid)
{
strfeatures="dialogwidth=500px;dialogheight=360px;center=yes;middle=yes ;help=no;status=no;scroll=no";
var url,strreturn;
url="selusex";
strreturn=windowmodaldialog(url,,strfeatures);
}
//返回模式对话框的值
function okbtn_onclick()
{
var commstr=;
windturnvalue=commstr;
window.close() ;
}
全屏幕打开 ie 窗口
var winwidth=screailwidth ;
var winheight=screailheight-20;
windon("mapx","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
xml doc = new activexobject(microsoft.xmldom)
xmldonc = false;
xsldoc = new activexobject(microsoft.xmldom)
xsldync = false;
xmldoc.load("tree.xml")
xsldod("trl")
foldertree.innerhtml = xmldcumentelement.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,各种
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 = stch(/^(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 (fullyear()==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]&&date()==r[4]&&d.gethours()==r[5]&&d.getminutes()==r[6]&&tseconds()==r[7]);
}
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 判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
/^([a-za-z_]{1})([w]*)$/g.test(str)
4.4 字符串替换函数.replace();
5、浏览器类
5.1 判断浏览器的类型
windvigatpname
5.2 判断ie的版本
window.navigator.appversion
5.3 判断客户端的分辨率
windoeen.height; window.screeth;
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 = year()==a[3]&&(month()+1)==a[4]&&d.getdate()==a[5];
}
else
{
var d = new date(a[3]+"/"+a[4]+"/"+a[5]);
var b = fullyear()==a[3]&&(d.getmonth()+1)==a[4]&&d.getdate()==a[5];
}
if (!b) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
}
return true;
}
画图:
id=s style="left: 0px; width: 392px; top: 0px; height: 240px" height=240 width=392 classid="clsid:369303c2-d7ac-11d0-89d5-00a0c90833e6"> </object> wingsurfacdegrees(0,0,0,30,50,60); awingsurfacradians(30,0,0,30,50,60); s.drawingsurface.line(10,10,100,100); 写注册表: var wshshell = wscript.createobject("wscript.shell"); wshshell.regwrite ("hkcu oftwareacmefortuneteller", 1, "reg_binary"); wshshegwrite ("hkcu oftwareacmefortunetellermindreader", "goocher!", "reg_sz"); var bkey = wshshell.regread ("hkcu oftwareacmefortuneteller"); wscript.echo (wshshell.regread ("hkcu oftwareacmefortunetellermindreader")); wshshell.regdelete ("hkcu oftwareacmefortunetellermindreader"); wshsheldelete ("hkcu oftwareacmefortuneteller"); wshshell.regdelete ("hkcu oftwareacme"); tablae相关(客户端动态增加行列) function numbercells() { var count=0; for (i=0; i < document.all.mytablgth; i++) { for (j=0; j < document.atable.rows(i).cells.length; j++) { documen.mytable.rows(i).cells(j).innertext = count; count++; } } } </script>
table>
body>
1.身份证严格验证:
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)$/t(sid))return false;
sid=sid.replace(/x$/i,"a");
if(acity[parseint(sbstr(0,2))]==null)return "error:非法地区";
birtshday=sid.substr(6,4)+"-"+number(sid.substr(10,2))+"-"+number(sid.substr(12,2));
var d=new date(sbirthday.replace(/-/g,"/"))
if(sbirthday!=(tfullyear()+"-"+ (d.getmonth()+1) + "-" + d.getdate()))return "error:非法生日";
for(var i = 17;i>=0;i --) isum += (mat(2,i) % 11) * parseint(sirat(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"),"");
documente(cidinfo("340524198002300019"),"<br/>")
documente(cidinfo("340524197711111111"),"<br/>")
documente(cidinfo("34052419800101001x"),"<br/>");
</script>
2.验证ip地址
function isip(s){
var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
var re=s.split(".")
return (rgth==4)?(check(re[0]) && check(re[1]) && check(re[2]) &&
check(re[3])):false
}
var s="202.197.78.129";
alert(isip(s))
3.加sp1后还能用的无边框窗口!!
<html xmlns:ie>
/*--- special thanks for andot ---*/
/*
this following code are designed and writen by windy_sk <seasonx@16>
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.stylderstyle=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_boyle.overflow= "hidden";
cw_boyle.backgroundcolor= "white";
cw_body.style.border= "solid black 1px";
content = contenlace(/]*)>/g," $1>"); temp += " temp += " onmouseup=parent.drag_up(event) onmousemove=pareag_move(event) onmousedown=parent.drag_down(event) onselectstart=return false oncontextmenu=return false>"; temp += " temp += " temp += "<span id=help onclick="alert(chromeless window for ie6 sp1 - ver 1.0nncode by windy_sknnspecial thanks for andot)" style=""+csstext+"font-family:system;padding-right:2px;">?"; temp += " onclick=paren_cw.hide();pareur() style=""+csstext+"font-family:webdings;" title=minimum>0span>"; temp += " onclick="thnertext=thnertext==1?2:1;paren_max=!paren_max;parent.show_cw();" style=""+csstext+"font-family:webdings;" title=maximum>1"; temp += " style=""+csstext+"font-family:system;padding-right:2px;" title=close>x temp += " temp += " temp += content; temp += "</div>"; temp += "td>tr>table>"; cw_bonerhtml = 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.includdth = cw_width; new_cw.docume.innertext = "1"; } else}{ new_cw.show(0, 0, scredth, screeght); new_cw.documelude.style.width = screen.width; } } window.onfocus = show_cw; windresize = show_cw; // move window var drag_x,drag_y,draging=false function drag_move(e){ if (draging){ new_cw.show(eenx-drag_x, e.screeny-drag_y, cw_width, cw_height); return false; } } function drag_down(e){ if(ton==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; elemetcapture(); } function drag_up(e){ draging=false; e.srcelement.releasecapture(); if(new_cw.documefsetwidth==scredth && new_cw.documefsetheight==screen.height) return; cw_top = reenx-drag_x; cw_left = eeny-drag_y; } 贴两个关于treeview的 script> treeview中如何在服务器端得到客户端设置后的节点选中状态 private void button1_click(object sender, system.eventargs e) { responste(treeviedes[0].checked); } <script language="javascript"> function set_check() { var nodeindex = "0"; var node=treeview1.gettreenode(nodeindex); node.setattribute("checked","true"); treeviewueevent(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;" 範例: false;" oncut="return false;"> //================================ //cookie操作 //================================ function getcookieval (offset) { var endstr = document.cookdexof (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookistring(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.cookistring(i, j) == arg) return getcookieval (j); i = document.cookdexof(" ", 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="+ expdatmtstring(); setcookie(cname,"",expdate); } function setcookie (name, value, expires) { document.cookie = name + "=" + escape(value) + "; expires=" + expiremtstring() ; } 一个可以在页面上随意画线、多边形、圆,填充等功能的js (part 1) var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz, jg_n4 = (documeyers && 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 endchild != "undefined" && typeof document.createrange != "undefined" && ypeotf (i = document.createrange()).setstartbefore != "undefined" && typeof i.createcontextualfragment != "undefined"); jg_ihtm = !jg_ie && !jg_dom && x && typeof erhtml != "undefined"; jg_fast = jg_ie && documen && !windora; jg_moz = jg_dom && typeof yle.mozopacity != "undefined"; } function pntdoc() { this.wnd.document.write(jg_fast? this.htmrpc() : this.htm); thi = ; } function pntcnvdom() { var x = document.createrange(); tstartbefore(thv); x = x.createcontextualfragment(jg_fast? this.htmrpc() : this.htm); thendchild(x); this.htm = ; } function pntcnvie() { this.csertadjacenthtml("beforeend", jg_fast? this.htmrpc() : this.htm); thi = ; } function pntcnvihtm() { this.cnerhtml += this.htm; thi = ; } function pntcnv() { this.htm = ; } function mkdiv(x, y, w, h) { thi += <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 : )+ ;"> } function mkdivie(x, y, w, h) { this.htm += %%+this.color+;+x+;+y+;+w+;+h+;; } function mkdivprt(x, y, w, h) { thm += border-left: + w + px solid + thlor + ;+ left: + x + px;+ top: + y + px;+ width:0px;+ height: + h + px;+ clip:rect(0,+w+px,+h+px,0);+ background-color: + thlor + (!jg_moz? ;overflow:hidden : )+ "><;/div>; } function mklyr(x, y, w, h) { this.htm += left=" + x + " + top=" + y + " + width=" + w + " + height=" + h + " + bgcolor=" + this.color + "><layer>n; } var regex = /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g; function htmrpc() { return this.htm.replace( regex, $1;left:$2;top:$3;width:$4;height:$5"> } function htmprtrpc() { return thi.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) { ar _vx2 = 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) { thdiv(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) { thdiv(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; } thiiv(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 = mas(y2-y1), x = x1, y = y1, yincr = (y1 > y2)? -1 : 1; var s = thioke; 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)? mail(_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) : matnd(_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) { thiiv(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) { thdiv(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) thiiv(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) thiiv(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); } } thiiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod); this.mkdiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod); } 一个可以在页面上随意画线、多边形、圆,填充等功能的js 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; part 2) ( 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; thivqds(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[pxgth] = 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[pxgth] = 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[_pngth] = _y-1; } else { _tt -= _aa*((_y<<1)-3); _st -= (_aa<<1)*(--_y); _pxb[_pxgth-1]--; } } } var ox = 0, oy = b, _oy = _pxb[0], l = pngth, 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]; thdiv(cx-x+1, cy-oy, 1, (oy<<1)+hod); thiiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod); ox = x; oy = pxt[i]; } } thdiv(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 function mkrect(x, y, w, h) { part 3) ( 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) { thiwline(x, y, x+w, y); thiwline(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;; thilic = font-style:italic;; thilic_bold = this.italic + this.bold; thid_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, thlor = arg.tolowercase();); this.setstroke = function(x) { this.stroke = x; if (!(x+1)) { thawline = mklindott; this.mkov = mkovdott; this.drawrect = mkrectdott; } else if (x-1 > 0) { thawline = mklin2d; this.mkov = mkov2d; this.drawrect = mkrect; } else { thiwline = mklin; this.mkov = mkov; this.drawrect = mkrect; } }; this.setprintable = function(arg) { this.printable = arg; if (jg_fast) { this.mkdiv = mkdivie; thirpc = arg? htmprtrpc : htmrpc; } else this.mkdiv = jg_n4? mklyr : arg? mkdivprt : mkdiv; }; this.setfont = function(fam, sz, sty) { thiam = fam; this.ftsz = sz; thsty = sty || foain; }; this.drawpolyline = this.drawpolyline = function(x, y, s) { for (var i=0 ; i thawline(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) { thiwpolyline(x, y); thawline(x[x.length-1], y[x.length-1], x[0], y[0]); }; this.drawellipse = thawoval = 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); thiiv(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++] = matnd((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) { thi += <div style="position:absolute;white-space:nowrap;+ left: + x + px;+ top: + y + px;+ font-family: + thiam + ;+ font-size: + thiz + ;+ color: + thior + ; + this.ftsty + ">+ txt + <div>; } this.drawimage = function(imgsrc, x, y, w, h) { this.htm += 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.cnerhtml = this.defhtm; }; thivqds = function(cx, cy, xl, xr, yt, yb, w, h) { this.mkdiv(xr+cx, yt+cy, w, h); thdiv(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); thlor = #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) : documetelementbyid? (this.wnd.documetelementbyid(id) || null) : null; this.defhtm = (this.cnv && therhtml)? this.cnerhtml : ; thint = 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; obsibility = "hidden"; oyle.display = "none"; 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(oyle.visibility == "hidden") { obj.style.visibility = "visible"; } else { obj.stylibility = "hidden"; } } function shownoneobject(obj) { if(obsplay == "none") { oyle.display = "block"; } else { obj.style.display = "none"; } } id=button1 onclick=showblankobject(show01); type=button value=blank name=button1> 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: #text {position: absolute; top: 400px; left: 400px; font: 18px arial; font-weight: 700; } these scripts are necessary for the three effects: var dhtml = (documenelementbyid || document.all || document.layers); function getobj(name) { if (documetelementbyid) { thi = documenelementbyid(name); this.style = documenelementbyid(name).style; } else if (document.all) { thi = documen[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.stylibility = (flag) ? hidden : visible } var texttop = 400; function move(amount) { if (!dhtml) return; var x = new getobj(text); texttop += amount; x.styl = texttop; } function changecol(col) { if (!dhtml) return; var x = new getobj(text); yle.color = col; } 一段实现datagrid的“编辑”、“取消”功能脚本,目的是不产生页面刷新 <script language="javascript"> var selectrow=""; var selectobject; function editcell(thisobject,type) { var id = thisobje; var buttonid="button"+type; var row=place(buttonid,""); if(type==1&&selectrngth>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; documen[name2].getattribute("style").display=visible2; if(type!=1) { if(documen[name1].value==1) documel[name2].checked=true; else ocumdent.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.parentelemelspan=type; var name; name=row+buttonid; document.all[name].getattribute("style").display="none"; if(type==1) { documen[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"; documen[name].getattribute("style").display="inline"; } } runat="server"> runat="server"> </itemtemplate> <asp:templatecolumn headertext="查询权"> runat="server"> runat="server" name="checkbox2"> </asp:templatecolumn> <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"> <headerstyle width="60px"> runat="server"> runat="server" name="checkbox4"> itemtemplate> /asp<:templatecolumn> <itemtemplate> src="images/checkboxunselect.gif" runat="server"> style="display: none" type="checkbox" runat="server" name="checkbox5"> <input id="text5" type="text" runat="server" style="display: none" name="text5"> asp:templatecolumn> runat="server"> runat="server" name="checkbox6"> </itemtemplate> <asp:templatecolumn headertext="导入权"> runat="server"> runat="server" name="checkbox7"> </asp:templatecolumn> 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"> 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> </columns> <head> 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> //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.menuxmumentelement; var sd = 0; documenelectstart = function(){return false;} document.aeebox.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 = thischildnodes()?"hasitems":"items"; innerhtml = "" + thisn.getattribute("text") +""; onmousedown = function(){ if(event.button != 1) return; if(this.getattribute("cn")){ thtattribute("open",!this.getattribute("open")); th.stylplay = thiattribute("open")?"inline":"none"; this.all.tags("img")[0].src = this.getattribute("open")?"http://www.blueidm/img/common/lof":"http://www.blueidea.com/img/common/logo.gif"; } if(io){ io.runtimestyle.csstext = ""; iattribute("selected",false); } io = this; this.setattribute("selected",true); thitimestyle.csstext = sc; } onmouseover = function(){ if(thtattribute("selected"))return; thitimestyle.csstext = hc; } onmouseout = function(){ if(thiattribute("selected"))return; this.runtimestyle.csstext = ""; } oncontextmenu = contextmenuhandle; onclick = clickhandle; } if(thisattribute("treeid") != null){ upobattribute("treeid",thisn.getattribute("treeid")); } if(thitattribute("href") != null){ upobj.setattribute("href",thisattribute("href")); } if(thitattribute("target") != null){ upotattribute("target",thisn.getattribute("target")); } nodeobj.appendchild(upobj); nodeobj.insertadjacenthtml("beforeend"," if(thischildnodes()){ var i; var nodes = thiildnodes; 本文发布于:2024-01-27 20:21:47,感谢您对本站的认可! 本文链接:https://www.4u4v.net/it/17063581072430.html 版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。"; ";
") 
留言与评论(共有 0 条评论)