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

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

admin
2010年4月26日 23:17 本文热度 7644

打开模式对话框
返回模式对话框的值
全屏幕打开 ie 窗口
脚本中中使用xml
一、验证类
1、数字验证内
2、时间类
3、表单类
4、字符类
5、浏览器类
6、结合类

[align=left]二、功能类
1、时间与相关控件类
2、表单类
3、打印类
4、事件类
5、网页设计类
6、树型结构。
7、无边框效果的制作
8、连动下拉框技术
9、文本排序
10,画图类,含饼、柱、矢量贝滋曲线
11,操纵客户端注册表类
12,div层相关(拖拽、显示、隐藏、移动、增加)
13,tablae相关(客户端动态增加行列,模拟进度条,滚动列表等)
14,各种object classid=>相关类,如播放器,flash与脚本互动等
16, 刷新/模拟无刷新 异步调用类(xmlhttp或iframe,frame) [/align]


一个可以在页面上随意画线、多边形、圆,填充等功能的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 != "undefined")
{
if (_pxb < _oy || pxt < oy)
{
x = pxl;
this.mkovqds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);
ox = x;
oy = pxt;
_oy = _pxb;
}
}
else
{
x = pxl;
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;
}
}
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 ; ithis.drawline(x, y, 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 < miny)
miny = array_y; if (array_y > maxy)
maxy = array_y;
}
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
this.mkdiv(polyints, y, polyints[i+1]-polyints+1, 1);
}
}
};
this.drawstring = function(txt, x, y)
{
this.htm += '
'+
txt +
'<\/div>';
}
this.drawimage = function(imgsrc, x, y, w, h)
{
this.htm += '
'+
''+
'<\/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";


dadd
ccc


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:
test text
#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的“编辑”、“取消”功能脚本,目的是不产生页面刷新
Copyright 2010-2024 ClickSun All Rights Reserved