LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

javascript 常用代码大全(超级收藏,强烈推荐)(2)

admin
2010年4月26日 23:17 本文热度 7906
[p]打开模式对话框 [br]返回模式对话框的值 [br]全屏幕打开 ie 窗口[br]脚本中中使用xml [br]一、验证类 [br]1、数字验证内[br]2、时间类[br]3、表单类[br]4、字符类[br]5、浏览器类[br]6、结合类[/p] [p][align=left]二、功能类 [br]1、时间与相关控件类[br]2、表单类 [br]3、打印类 [br]4、事件类 [br]5、网页设计类[br]6、树型结构。[br]7、无边框效果的制作 [br]8、连动下拉框技术 [br]9、文本排序 [br]10,画图类,含饼、柱、矢量贝滋曲线 [br]11,操纵客户端注册表类 [br]12,div层相关(拖拽、显示、隐藏、移动、增加) [br]13,tablae相关(客户端动态增加行列,模拟进度条,滚动列表等) [br]14,各种object classid=>相关类,如播放器,flash与脚本互动等 [br]16, 刷新/模拟无刷新 异步调用类(xmlhttp或iframe,frame) [/align][/p] [br]一个可以在页面上随意画线、多边形、圆,填充等功能的js (part 2) [br]function mkov2d(left, top, width, height) [br]{ [br]var s = this.stroke; [br]width += s-1; [br]height += s-1; [br]var a = width>>1, b = height>>1, [br]wod = width&1, hod = (height&1)+1, [br]cx = left+a, cy = top+b, [br]x = 0, y = b, [br]aa = (a*a)<<1, bb = (b*b)<<1, [br]st = (aa>>1)*(1-(b<<1)) + bb, [br]tt = (bb>>1) - aa*((b<<1)-1); if (s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0)) [br]{ [br]var ox = 0, oy = b, [br]w, h, [br]pxl, pxr, pxt, pxb, pxw; [br]while (y > 0) [br]{ [br]if (st < 0) [br]{ [br]st += bb*((x<<1)+3); [br]tt += (bb<<1)*(++x); [br]} [br]else if (tt < 0) [br]{ [br]st += bb*((x<<1)+3) - (aa<<1)*(y-1); [br]tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3); [br]w = x-ox; [br]h = oy-y; if (w-1) [br]{ [br]pxw = w+1+(s&1); [br]h = s; [br]} [br]else if (h-1) [br]{ [br]pxw = s; [br]h += 1+(s&1); [br]} [br]else pxw = h = s; [br]this.mkovqds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h); [br]ox = x; [br]oy = y; [br]} [br]else [br]{ [br]tt -= aa*((y<<1)-3); [br]st -= (aa<<1)*(--y); [br]} [br]} [br]this.mkdiv(cx-a, cy-oy, s, (oy<<1)+hod); [br]this.mkdiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod); [br]} else [br]{ [br]var _a = (width-((s-1)<<1))>>1, [br]_b = (height-((s-1)<<1))>>1, [br]_x = 0, _y = _b, [br]_aa = (_a*_a)<<1, _bb = (_b*_b)<<1, [br]_st = (_aa>>1)*(1-(_b<<1)) + _bb, [br]_tt = (_bb>>1) - _aa*((_b<<1)-1), pxl = new array(), [br]pxt = new array(), [br]_pxb = new array(); [br]pxl[0] = 0; [br]pxt[0] = b; [br]_pxb[0] = _b-1; [br]while (y > 0) [br]{ [br]if (st < 0) [br]{ [br]st += bb*((x<<1)+3); [br]tt += (bb<<1)*(++x); [br]pxl[pxl.length] = x; [br]pxt[pxt.length] = y; [br]} [br]else if (tt < 0) [br]{ [br]st += bb*((x<<1)+3) - (aa<<1)*(y-1); [br]tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3); [br]pxl[pxl.length] = x; [br]pxt[pxt.length] = y; [br]} [br]else [br]{ [br]tt -= aa*((y<<1)-3); [br]st -= (aa<<1)*(--y); [br]} if (_y > 0) [br]{ [br]if (_st < 0) [br]{ [br]_st += _bb*((_x<<1)+3); [br]_tt += (_bb<<1)*(++_x); [br]_pxb[_pxb.length] = _y-1; [br]} [br]else if (_tt < 0) [br]{ [br]_st += _bb*((_x<<1)+3) - (_aa<<1)*(_y-1); [br]_tt += (_bb<<1)*(++_x) - _aa*(((_y--)<<1)-3); [br]_pxb[_pxb.length] = _y-1; [br]} [br]else [br]{ [br]_tt -= _aa*((_y<<1)-3); [br]_st -= (_aa<<1)*(--_y); [br]_pxb[_pxb.length-1]--; [br]} [br]} [br]} var ox = 0, oy = b, [br]_oy = _pxb[0], [br]l = pxl.length, [br]w, h; [br]for (var i = 0; i < l; i++) [br]{ [br]if (typeof _pxb[i] != "undefined") [br]{ [br]if (_pxb[i] < _oy || pxt[i] < oy) [br]{ [br]x = pxl[i]; [br]this.mkovqds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy); [br]ox = x; [br]oy = pxt[i]; [br]_oy = _pxb[i]; [br]} [br]} [br]else [br]{ [br]x = pxl[i]; [br]this.mkdiv(cx-x+1, cy-oy, 1, (oy<<1)+hod); [br]this.mkdiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod); [br]ox = x; [br]oy = pxt[i]; [br]} [br]} [br]this.mkdiv(cx-a, cy-oy, 1, (oy<<1)+hod); [br]this.mkdiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod); [br]} [br]} [br]function mkovdott(left, top, width, height) [br]{ [br]var a = width>>1, b = height>>1, [br]wod = width&1, hod = height&1, [br]cx = left+a, cy = top+b, [br]x = 0, y = b, [br]aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1, [br]st = (aa2>>1)*(1-(b<<1)) + bb, [br]tt = (bb>>1) - aa2*((b<<1)-1), [br]drw = true; [br]while (y > 0) [br]{ [br]if (st < 0) [br]{ [br]st += bb*((x<<1)+3); [br]tt += (bb<<1)*(++x); [br]} [br]else if (tt < 0) [br]{ [br]st += bb*((x<<1)+3) - aa4*(y-1); [br]tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3); [br]} [br]else [br]{ [br]tt -= aa2*((y<<1)-3); [br]st -= aa4*(--y); [br]} [br]if (drw) this.mkovqds(cx, cy, -x, x+wod, -y, y+hod, 1, 1); [br]drw = !drw; [br]} [br]} [br]一个可以在页面上随意画线、多边形、圆,填充等功能的js (part 3) function mkrect(x, y, w, h) [br]{ [br]var s = this.stroke; [br]this.mkdiv(x, y, w, s); [br]this.mkdiv(x+w, y, s, h); [br]this.mkdiv(x, y+h, w+s, s); [br]this.mkdiv(x, y+s, s, h-s); [br]} [br]function mkrectdott(x, y, w, h) [br]{ [br]this.drawline(x, y, x+w, y); [br]this.drawline(x+w, y, x+w, y+h); [br]this.drawline(x, y+h, x+w, y+h); [br]this.drawline(x, y, x, y+h); [br]} [br]function jsgfont() [br]{ [br]this.plain = 'font-weight:normal;'; [br]this.bold = 'font-weight:bold;'; [br]this.italic = 'font-style:italic;'; [br]this.italic_bold = this.italic + this.bold; [br]this.bold_italic = this.italic_bold; [br]} [br]var font = new jsgfont(); [br]function jsgstroke() [br]{ [br]this.dotted = -1; [br]} [br]var stroke = new jsgstroke(); [br]function jsgraphics(id, wnd) [br]{ [br]this.setcolor = new function('arg', 'this.color = arg.tolowercase();'); this.setstroke = function(x) [br]{ [br]this.stroke = x; [br]if (!(x+1)) [br]{ [br]this.drawline = mklindott; [br]this.mkov = mkovdott; [br]this.drawrect = mkrectdott; [br]} [br]else if (x-1 > 0) [br]{ [br]this.drawline = mklin2d; [br]this.mkov = mkov2d; [br]this.drawrect = mkrect; [br]} [br]else [br]{ [br]this.drawline = mklin; [br]this.mkov = mkov; [br]this.drawrect = mkrect; [br]} [br]}; [br]this.setprintable = function(arg) [br]{ [br]this.printable = arg; [br]if (jg_fast) [br]{ [br]this.mkdiv = mkdivie; [br]this.htmrpc = arg? htmprtrpc : htmrpc; [br]} [br]else this.mkdiv = jg_n4? mklyr : arg? mkdivprt : mkdiv; [br]}; [br]this.setfont = function(fam, sz, sty) [br]{ [br]this.ftfam = fam; [br]this.ftsz = sz; [br]this.ftsty = sty || font.plain; [br]}; [br]this.drawpolyline = this.drawpolyline = function(x, y, s) [br]{ [br]for (var i=0 ; i>1, b = (h -= 1)>>1, [br]wod = (w&1)+1, hod = (h&1)+1, [br]cx = left+a, cy = top+b, [br]x = 0, y = b, [br]ox = 0, oy = b, [br]aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1, [br]st = (aa2>>1)*(1-(b<<1)) + bb, [br]tt = (bb>>1) - aa2*((b<<1)-1), [br]pxl, dw, dh; [br]if (w+1) while (y > 0) [br]{ [br]if (st < 0) [br]{ [br]st += bb*((x<<1)+3); [br]tt += (bb<<1)*(++x); [br]} [br]else if (tt < 0) [br]{ [br]st += bb*((x<<1)+3) - aa4*(y-1); [br]pxl = cx-x; [br]dw = (x<<1)+wod; [br]tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3); [br]dh = oy-y; [br]this.mkdiv(pxl, cy-oy, dw, dh); [br]this.mkdiv(pxl, cy+oy-dh+hod, dw, dh); [br]ox = x; [br]oy = y; [br]} [br]else [br]{ [br]tt -= aa2*((y<<1)-3); [br]st -= aa4*(--y); [br]} [br]} [br]this.mkdiv(cx-a, cy-oy, w+1, (oy<<1)+hod); [br]}; this.fillpolygon = function(array_x, array_y) [br]{ [br]var i; [br]var y; [br]var miny, maxy; [br]var x1, y1; [br]var x2, y2; [br]var ind1, ind2; [br]var ints; var n = array_x.length; if (!n) return; [br]miny = array_y[0]; [br]maxy = array_y[0]; [br]for (i = 1; i < n; i++) [br]{ [br]if (array_y[i] < miny) [br]miny = array_y[i]; if (array_y[i] > maxy) [br]maxy = array_y[i]; [br]} [br]for (y = miny; y <= maxy; y++) [br]{ [br]var polyints = new array(); [br]ints = 0; [br]for (i = 0; i < n; i++) [br]{ [br]if (!i) [br]{ [br]ind1 = n-1; [br]ind2 = 0; [br]} [br]else [br]{ [br]ind1 = i-1; [br]ind2 = i; [br]} [br]y1 = array_y[ind1]; [br]y2 = array_y[ind2]; [br]if (y1 < y2) [br]{ [br]x1 = array_x[ind1]; [br]x2 = array_x[ind2]; [br]} [br]else if (y1 > y2) [br]{ [br]y2 = array_y[ind1]; [br]y1 = array_y[ind2]; [br]x2 = array_x[ind1]; [br]x1 = array_x[ind2]; [br]} [br]else continue; if ((y >= y1) && (y < y2)) [br]polyints[ints++] = math.round((y-y1) * (x2-x1) / (y2-y1) + x1); else if ((y == maxy) && (y > y1) && (y <= y2)) [br]polyints[ints++] = math.round((y-y1) * (x2-x1) / (y2-y1) + x1); [br]} [br]polyints.sort(integer_compare); for (i = 0; i < ints; i+=2) [br]{ [br]w = polyints[i+1]-polyints[i] [br]this.mkdiv(polyints[i], y, polyints[i+1]-polyints[i]+1, 1); [br]} [br]} [br]}; [br]this.drawstring = function(txt, x, y) [br]{ [br]this.htm += '
'+ [br]txt + [br]'<\/div>'; [br]} [br]this.drawimage = function(imgsrc, x, y, w, h) [br]{ [br]this.htm += '
'+ [br]''+ [br]'<\/div>'; [br]} [br]this.clear = function() [br]{ [br]this.htm = ""; [br]if (this.cnv) this.cnv.innerhtml = this.defhtm; [br]}; [br]this.mkovqds = function(cx, cy, xl, xr, yt, yb, w, h) [br]{ [br]this.mkdiv(xr+cx, yt+cy, w, h); [br]this.mkdiv(xr+cx, yb+cy, w, h); [br]this.mkdiv(xl+cx, yb+cy, w, h); [br]this.mkdiv(xl+cx, yt+cy, w, h); [br]}; this.setstroke(1); [br]this.setfont('verdana,geneva,helvetica,sans-serif', string.fromcharcode(0x31, 0x32, 0x70, 0x78), font.plain); [br]this.color = '#000000'; [br]this.htm = ''; [br]this.wnd = wnd || window; if (!(jg_ie || jg_dom || jg_ihtm)) chkdhtm(); [br]if (typeof id != 'string' || !id) this.paint = pntdoc; [br]else [br]{ [br]this.cnv = document.all? (this.wnd.document.all[id] || null) [br]: document.getelementbyid? (this.wnd.document.getelementbyid(id) || null) [br]: null; [br]this.defhtm = (this.cnv && this.cnv.innerhtml)? this.cnv.innerhtml : ''; [br]this.paint = jg_dom? pntcnvdom : jg_ie? pntcnvie : jg_ihtm? pntcnvihtm : pntcnv; [br]} this.setprintable(false); [br]} function integer_compare(x,y) [br]{ [br]return (x < y) ? -1 : ((x > y)*1); [br]} [br] js 中,一些东西不可用的三种展现方式。 [br]我们在web项目中,有时候需要在用户点击某个东西的时候,一些东西不可用。如果在客户端实现。最简单的就是利用disabled 。下面罗列的其中三种方式:依次是:不可用(disabled);用一个空白来代替这个地方(blank);这个区域为空(none)。具体可以查看这个blog的源文件: [br]obj.disabled = false; obj.style.visibility = "hidden"; obj.style.display = "none"; [br]

[br]
dadd [br]
ccc
[br]

[br]on this page i explain a simple dhtml example script that features invisibility, moving and the changing of text colour. [br]example [br]test textmake test text invisible. [br]make test text visible. [br]move test text 50 pixels down. [br]move test text 50 pixels up. [br]change colour to red. [br]change colour to blue. [br]change colour to black. [br]change the font style to italic. [br]change the font style to normal. [br]change the font family to 'times'. [br]change the font family to 'arial'. [br]the script [br]the scripts work on this html element:
test text
#text {position: absolute; [br]top: 400px; [br]left: 400px; [br]font: 18px arial; [br]font-weight: 700; [br]} these scripts are necessary for the three effects: var dhtml = (document.getelementbyid || document.all || document.layers); function getobj(name) [br]{ [br] if (document.getelementbyid) [br] { [br] this.obj = document.getelementbyid(name); [br]this.style = document.getelementbyid(name).style; [br] } [br] else if (document.all) [br] { [br]this.obj = document.all[name]; [br]this.style = document.all[name].style; [br] } [br] else if (document.layers) [br] { [br] this.obj = document.layers[name]; [br] this.style = document.layers[name]; [br] } [br]} function invi(flag) [br]{ [br]if (!dhtml) return; [br]var x = new getobj('text'); [br]x.style.visibility = (flag) ? 'hidden' : 'visible' [br]} var texttop = 400; function move(amount) [br]{ [br]if (!dhtml) return; [br]var x = new getobj('text'); [br]texttop += amount; [br]x.style.top = texttop; [br]} [br]function changecol(col) [br]{ [br]if (!dhtml) return; [br]var x = new getobj('text'); [br]x.style.color = col; [br]} [br]一段实现datagrid的“编辑”、“取消”功能脚本,目的是不产生页面刷新 [br]
Copyright 2010-2024 ClickSun All Rights Reserved