//自定义的apply,call
Function.prototype.apply =
function (obj, argu) {
if (obj) obj.constructor.prototype._caller =
this ;
var argus =
new Array ();
for (
var i=0;i
argus[i] = "argu[" + i + "]" ; var r; eval("r = " + (obj ? ("obj._caller(" + argus.join("," ) + ");" ) : ("this(" + argus.join("," ) + ");" ))); return r; }; Function.prototype.call = function (obj) { var argu = new Array (); for (var i=1;i argu[i-1] = arguments[i]; return this .apply(obj, argu); };
//下载文件
function DownURL(strRemoteURL,strLocalURL) { try { var xmlHTTP=new ActiveXObject ("Microsoft.XMLHTTP" ); xmlHTTP.open("Get" ,strRemoteURL,false ); xmlHTTP.send(); var adodbStream=new ActiveXObject ("ADODB.Stream" ); adodbStream.Type=1;//1=adTypeBinary adodbStream.Open(); adodbStream.write(xmlHTTP.responseBody); adodbStream.SaveToFile(strLocalURL,2); adodbStream.Close(); adodbStream=null ; xmlHTTP=null ; } catch (e) { window.confirm("下载URL出错!" ); } //window.confirm("下载完成." ); }
//检验连接是否有效
function getXML(URL) { var xmlhttp = new ActiveXObject ("microsoft.xmlhttp" ); xmlhttp.Open("GET" ,URL, false ); try { xmlhttp.Send(); } catch (e){} finally { var result = xmlhttp.responseText; if (result) { if (xmlhttp.Status==200) { return (true ); } else { return (false ); } } else { return (false ); } } }
//POST代替FORM
//readyState是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成
//检查网页是否存在
function CheckURL(URL) { var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP" ); xmlhttp.Open("GET" ,URL, false ); try { xmlhttp.Send(); var result = xmlhttp.status; } catch (e) {return (false ); } if (result==200) { return true ; } xmlhttp = null ; return false ; }
//连接数据库
>
//用 JavaScript 写服务器端连接数据库的代码示例 var conn =
new ActiveXObject (
"ADODB.Connection" );
conn.Open(
"Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; " +
"Password=; Initial Catalog=pubs" );
var rs =
new ActiveXObject (
"ADODB.Recordset" );
var sql=
"select * from authors" ;
rs.open(sql, conn);
shtml =
""; shtml +="
au_id
au_lname
au_fname
phone
address
city
state
zip
" ; while (!rs.EOF) { shtml += "
" + rs("au_id" ) + "
" + rs("au_lname" ) + "
" + rs("au_fname" ) + "
" + rs("phone" ) + "
" + rs("address" ) + "
" + rs("city" ) + "
" + rs("state" ) + "
" + rs("zip" ) + "
" ; rs.moveNext; } shtml += "
" ;
document.write(shtml);
rs.close();
rs =
null ;
conn.close();
conn =
null ;
//使用数据岛
srno: "76" > times: "76" > "first" TYPE=button value=" onclick="xmldate.recordset.moveFirst()" > "prev" TYPE=button value=" onclick="xmldate.recordset.movePrevious()" > "next" TYPE=button value="下一条记录>" onclick="xmldate.recordset.moveNext()" > "last" TYPE=button value="最后一条记录>>" onclick="xmldate.recordset.moveLast()" > "Add" TYPE=button value="添加新记录" onclick="xmldate.recordset.addNew()" > "xmldate"> 20041025-01 null 20041101-09 2004年10月1日2点22分0秒
//获得参数
//可编辑Select
"width:100px;height:21px;font-size:10pt;">"width:18px;border:0px solid red;" >"r00" style="margin-left:-100px;width:118px; background-color:#FFEEEE;" onChange="document.all.re_name.value=this.value;" > "1">11111111
"2">222222 "3">333333
//设置光标位置
function getCaret(textbox) { var control = document.activeElement; textbox.focus(); var rang = document.selection.createRange(); rang.setEndPoint("StartToStart" ,textbox.createTextRange()) control.focus(); return rang.text.length; } function setCaret(textbox,pos) { try { var r =textbox.createTextRange(); r.moveStart('character',pos); r.collapse(true ); r.select(); } catch (e) {} } function selectLength(textbox,start,len) { try { var r =textbox.createTextRange(); r.moveEnd('character',len-(textbox.value.length-start)); r.moveStart('character',start); r.select(); } catch (e) {//alert(e.description)} } function insertAtCaret(textbox,text) { textbox.focus(); document.selection.createRange().text = text; }
//页内查找
function findInPage(str) { var txt, i, found,n = 0; if (str == "" ) { return false ; } txt = document.body.createTextRange(); for (i = 0; i false; i++) { txt.moveStart("character" , 1); txt.moveEnd("textedit" ); } if (found) { txt.moveStart("character" , -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; } else { if (n > 0) { n = 0; findInPage(str); } else { alert(str + "... 您要找的文字不存在。
\n请试着输入页面中的关键字再次查找!" ); } } return false ; }
//书
//自定义提示条
" );
function showPopupText(){
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if (o.alt!=
null && o.alt!=
"" ){o.dypop=o.alt;o.alt=
"" };
if (o.title!=
null && o.title!=
"" ){o.dypop=o.title;o.title=
"" };
if (o.dypop!=sPop) {
sPop=o.dypop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if (sPop==
null || sPop==
"" ) {
dypopLayer.innerHTML=
"" ;
dypopLayer.style.filter=
"Alpha()" ;
dypopLayer.filters.Alpha.opacity=0;
}
else {
if (o.dyclass!=
null ) popStyle=o.dyclass
else popStyle=
"cPopText" ;
curShow=setTimeout(
"showIt()" ,tPopWait);
}
}
}
function showIt(){
dypopLayer.className=popStyle;
dypopLayer.innerHTML=sPop;
popWidth=dypopLayer.clientWidth;
popHeight=dypopLayer.clientHeight;
if (MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if (MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
dypopLayer.style.filter=
"Alpha(Opacity=0)" ;
fadeOut();
}
function fadeOut(){
if (dypopLayer.filters.Alpha.opacity
dypopLayer.filters.Alpha.opacity+=showPopStep; tFadeOut=setTimeout("fadeOut()" ,1); } else { dypopLayer.filters.Alpha.opacity=popOpacity; tFadeWaiting=setTimeout("fadeIn()" ,tPopShow); } } function fadeIn(){ if (dypopLayer.filters.Alpha.opacity>0) { dypopLayer.filters.Alpha.opacity-=1; tFadeIn=setTimeout("fadeIn()" ,1); } } document.onmouseover=showPopupText;
//插入文字
document.onclick =function (){ var oSource = window.event.srcElement; if (oSource.tagName!="DIV" ) return false ; var sel = document.selection; if (sel!=null ) { var rng = sel.createRange(); if (rng!=null ) rng.pasteHTML("插入文字 " ); } }
//netscapte下操作xml
doc = new ActiveXObject ("Msxml2.DOMDocument" ); doc = new ActiveXObject ("Microsoft.XMLDOM" ) ->> doc = (new DOMParser()).parseFromString(sXML,'text/xml')
//判断键值
"Content-Type" content="text/html; charset=gb2312" > //Javascript Document.
请按任意一个键。。。。
//禁止FSO
1.注销组件 regsvr32 /u scrrun.dll 2.修改PROGID HKEY_CLASSES_ROOT\Scripting.FileSystemObject Scripting.FileSystemObject 3.对于使用object的用户,修改HKEY_CLASSES_ROOT\Scripting.
//省略号
"width: 120px; height: 50px; border: 1px solid blue; overflow: hidden; text-overflow:ellipsis"> 就是比如有一行文字,很长,表格内一行显示不下.
//检测media play版本
"oClientCaps" style="{behavior:url(#default#clientcaps)}" /> <script> <BR><SPAN style="COLOR: #0000ff">var flash=<SPAN style="COLOR: #ff00ff">""; <BR> WMPVersion= oClientCaps.getComponentVersion(<SPAN style="COLOR: #ff00ff">"{22D6F312-B0F6-11D0-94AB-0080C74C7E95}",<SPAN style="COLOR: #ff00ff">"ComponentID"); <BR> <SPAN style="COLOR: #0000ff">if (WMPVersion != <SPAN style="COLOR: #ff00ff">"") { <BR> flash = <SPAN style="COLOR: #ff00ff">""; <BR> <SPAN style="COLOR: #0000ff">var version = WMPVersion.split(<SPAN style="COLOR: #ff00ff">","); <BR> <SPAN style="COLOR: #0000ff">var i; <BR> for (i = 0; i < version.length; i++) { <BR> <SPAN style="COLOR: #0000ff">if (i != 0) <BR> flash += <SPAN style="COLOR: #ff00ff">"."; <BR> flash += version[i]; <BR> } <BR> document.write(<SPAN style="COLOR: #ff00ff">"您的Windows Media Player 版本是:"+flash+<SPAN style="COLOR: #ff00ff">"<p>"); <BR> } <BR></script>
//图象按比例
".." onload =
"DrawImage(this)" >
//细线Select
span style="border:1px solid #000000; position:absolute; overflow:hidden;" > select style="margin:-2px;" > option >1111/option > option >11111111111111/option > option >111111111/option > /select >/span >
//Import
function Import() {
for(
var i=0; i
var file = arguments[i]; if ( file.match(/\.js$/i)) document.write('
//js枚举
function getComputerName() { var objWMIService = GetObject("Winmgmts:root\cimv2" ); for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext()) { var getComputer = e.item(); return getComputer.Name; } }
//条件编译
<script> <BR><SPAN style="COLOR: #008000">/*@cc_on @*/ <BR><SPAN style="COLOR: #008000">/*@if (@_win32 && @_jscript_version>5) <BR>function window.confirm(str) <BR>{ <BR> execScript("n = msgbox('"+ str +"', 257)", "vbscript"); <BR> return(n == 1); <BR>} <BR>@end @*/ <BR></script>
//取得innerText
//mergeAttributes 复制所有读/写标签属性到指定元素。
<script> <BR><SPAN style="COLOR: #0000ff">function fnMerge(){ <BR>oSource.children[1].mergeAttributes(oSource.children[0]); <BR>} <BR></script>
ID="oDiv" ATTRIBUTE1="true" ATTRIBUTE2="true" onclick="alert('click');" onmouseover="this.style.color='#0000FF';" onmouseout="this.style.color='#000000';" > This is a sample DIV element.
"oDiv2"> This is another sample DIV element.
TYPE=
"button" VALUE=
"Merge Attributes" onclick=
"fnMerge()" >
将选中内容保存为html
New Document "Generator" CONTENT=
"EditPlus" >
"Author" CONTENT=
"" >
"Keywords" CONTENT=
"" >
"Description" CONTENT=
"" >
显示版块帖子
版块帖子分页
显示单个帖子
发送新帖
帖子回复
个人登陆
留言的回复功能
"save()" value=
"aa" >
判断是刷新还是离开
判断是刷新还是关闭-www.51windows.Net "Content-Type" content="text/html; charset=gb2312" > "Author" CONTENT="51windows,海娃,haiwa" > "Description" CONTENT="Power by 51windows.Net" > <script> <BR><SPAN style="COLOR: #0000ff">function CloseOpen() { <BR> <SPAN style="COLOR: #0000ff">if(event.clientX<=0 && event.clientY<0) { <BR> alert(<SPAN style="COLOR: #ff00ff">"关闭"); <BR> } <BR> else <BR> { <BR> alert(<SPAN style="COLOR: #ff00ff">"刷新或离开"); <BR> } <BR>} <BR></script> "CloseOpen()">
获得光标位置
<script> <BR><SPAN style="COLOR: #0000ff">function getCursorPosition(){ <BR><SPAN style="COLOR: #0000ff">var src = event.srcElement <BR><SPAN style="COLOR: #0000ff">var oTR = src.createTextRange() <BR><SPAN style="COLOR: #0000ff">var oSel = document.selection.createRange() <BR><SPAN style="COLOR: #0000ff">var textLength = src.innerText.length <BR><SPAN style="COLOR: #0000ff">var line, char, total, cl <BR>oTR.moveToPoint(oSel.offsetLeft, oSel.offsetTop) <BR>oTR.moveStart(<SPAN style="COLOR: #ff00ff">"character", -1*textLength) <BR>cl = oTR.getClientRects() <BR>line = cl.length <BR>total = oTR.text.length <BR>oTR.moveToPoint(cl[cl.length-1].left, cl[cl.length-1].top) <BR>oTR.moveStart(<SPAN style="COLOR: #ff00ff">"character", -1*textLength) <BR>char = total - oTR.text.length <BR><SPAN style="COLOR: #0000ff">if (oSel.offsetTop != cl[cl.length-1].top) {line++; char = 0} <BR><SPAN style="COLOR: #0000ff">else <SPAN style="COLOR: #0000ff">if (src.createTextRange().text.substr(oTR.text.length, 2) == <SPAN style="COLOR: #ff00ff">"\r\n") char -= 2 <BR>window.status = <SPAN style="COLOR: #ff00ff">"行: " + line +<SPAN style="COLOR: #ff00ff">", 列: " + char + <SPAN style="COLOR: #ff00ff">", 第 " + total + <SPAN style="COLOR: #ff00ff">" 个字符" <BR>} <BR></script>
TextRange的常用方法
collapse([bStart]) 收起选区,并移动Range的插入点 bStart true (移到开头,default) false (移到末尾) expand(sUnit) 展开选区,让单位所包括的选区被包含进来 findText(sText [, iSearchScope] [, iFlags]) 在Range中查找sText iSearchScope 开始位置,负数方向搜索 iFlags 1(向后搜索) 2(整词匹配) 4(区别大小写) moveStart(sUnit [, iCount]) moveEnd(sUnit [, iCount]) 移动Range的开头或结尾 sUnit character(字) word(词) sentence(句) textedit(Range) iCount 移动数量,默认为1 moveToPoint(iX, iY) 移动光标到坐标(iX,iY) pasteHTML(sHTMLText) 替换Range中的html scrollIntoView([bAlignToTop]) 滚动使之在当前窗口显示 bAlignToTop true (Range在窗口开头) false (Range在窗口底部) select() 让选区选中状态
事件源对象 event.srcElement.tagName event.srcElement.type
捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture();
事件按键 event.keyCode event.shiftKey event.altKey event.ctrlKey
事件返回值 event.returnValue
鼠标位置 event.x event.y
窗体活动元素 document.activeElement
绑定事件 document.captureEvents(Event.KEYDOWN);
访问窗体元素 document.all("txt").focus(); document.all("txt").select();
窗体命令 document.execCommand
窗体COOKIE document.cookie
菜单事件 document.oncontextmenu
创建元素 document.createElement("SPAN");
根据鼠标获得元素: document.elementFromPoint(event.x,event.y).tagName=="TDdocument.elementFromPoint(event.x,event.y).appendChild(ms)
窗体图片 document.images[索引]
窗体事件绑定 document.onmousedown=scrollwindow;