javascript

位置:IT落伍者 >> javascript >> 浏览文章

javascript技巧参考


发布日期:2024年03月08日
 
javascript技巧参考

事件源对象

eventsrcElementtagName

eventsrcElementtype

捕获释放

eventsrcElementsetCapture();

eventsrcElementreleaseCapture();

事件按键

eventkeyCode

eventshiftKey

eventaltKey

eventctrlKey

事件返回值

eventreturnValue

鼠标位置

eventx

eventy

窗体活动元素

documentactiveElement

绑定事件

documentcaptureEvents(EventKEYDOWN);

访问窗体元素

documentall(txt)focus();

documentall(txt)select();

窗体命令

documentexecCommand

窗体COOKIE

okie

菜单事件

documentoncontextmenu

创建元素

documentcreateElement(SPAN);

根据鼠标获得元素

documentelementFromPoint(eventxeventy)tagName==TD

documentelementFromPoint(eventxeventy)appendChild(ms)

窗体图片

documentimages[索引]

窗体事件绑定

documentonmousedown=scrollwindow;

元素

document窗体elements[索引]

对象绑定事件

documentallxxxdetachEvent(onclicka);

插件数目

navigatorplugins

取变量类型

typeof($js_libpath) == undefined

下拉框

下拉框options[索引]

下拉框optionslength

查找对象

documentgetElementsByName(r);

documentgetElementById(id);

定时

timer=setInterval(scrollwindow()delay);

clearInterval(timer);

UNCODE编码

escape() unescape

父对象

objparentElement(dHTML)

objparentNode(dom)

交换表的行

TableIDmoveRow()

替换CSS

documentallCSSshref = aCSS;

并排显示

display:inline

隐藏焦点

hidefocus=true

根据宽度换行

自动刷新

<meta HTTPEQUIV=refresh CONTENT=;URL=>

简单邮件

<a mailto:?subject=ccc&body=xxxyyy>

快速转到位置

objscrollIntoView(true)

<a name=first>

<a #first>anchors</a>

网页传递参数

locationsearch();

可编辑

ntenteditable=true

执行菜单命令

objexecCommand

双字节字符

/[^\x\xff]/

汉字

/[\ue\ufa]/

让英文字符串超出表格宽度自动换行

wordwrap: breakword; wordbreak: breakall;

透明背景

<IFRAME src=// width= height= allowtransparency></iframe>

获得style内容

objstyleCSSText

HTML标签

documentdocumentElementinnerHTML

第一个style标签

documentstyleSheets[]

style标签里的第一个样式

documentstyleSheets[]rules[]

防止点击空链接时页面往往重置到页首端

<a JavaScript:function()>word</a>

上一网页源

ASP:

requestservervariables(HTTP_REFERER)

JavaScript:

documentreferrer

释放内存

CollectGarbage();

禁止右键

documentoncontextmenu = function() { return false;}

禁止保存

<noscript><iframe src=></iframe></noscript>

禁止选取<body oncontextmenu=return false ondragstart=return false onselectstart =return false onselect=documentselectionempty() oncopy=documentselectionempty() onbeforecopy=return falseonmouseup=documentselectionempty()>

禁止粘贴

<input type=text onpaste=return false>

地址栏图标

<link rel=Shortcut Icon >

faviconico 名字最好不变*放虚拟目录根目录下

收藏栏图标

<link rel=Bookmark >

查看源码

<input type=button value=查看网页源代码 onclick=windowlocation = viewsource:+ >

关闭输入法

<input >

自动全选

<input type=text name=text value= onfocus=thisselect()>

ENTER键可以让光标移到下一个输入框

<input onkeydown=if(eventkeyCode==)eventkeyCode=>

文本框的默认值

<input type=text value= onfocus=alert(thisdefaultValue)>

title换行

objtitle = sdfs

获得时间所代表的微秒

var n = new Date(replace(//g \/))getTime()

窗口是否关闭

winclosed

checkbox扁平

<input type=checkbox ><br>

获取选中内容

documentselectioncreateRange()duplicate()text

自动完成功能

<input type=text autocomplete=on>打开该功能

<input type=text autocomplete=off>关闭该功能

窗口最大化

<body onload=windowresizeTo(windowscreenwidth windowscreenheight);windowmoveTo()>

无关闭按钮IE

windowopen( meizz fullscreen=);

统一编码/解码

alert(decodeURIComponent(encodeURIComponent(//你?as= hehe)))

encodeURIComponent对:/;?也编码

表格行指示

<tr onmouseover=thisbgColor=#fff onmouseout=thisbgColor=#ffffff>

//各种尺寸

s += \r\n网页可见区域宽+ documentbodyclientWidth;

s += \r\n网页可见区域高+ documentbodyclientHeight;

s += \r\n网页可见区域高+ documentbodyoffsetWeight + (包括边线的宽);

s += \r\n网页可见区域高+ documentbodyoffsetHeight + (包括边线的宽);

s += \r\n网页正文全文宽+ documentbodyscrollWidth;

s += \r\n网页正文全文高+ documentbodyscrollHeight;

s += \r\n网页被卷去的高+ documentbodyscrollTop;

s += \r\n网页被卷去的左+ documentbodyscrollLeft;

s += \r\n网页正文部分上+ windowscreenTop;

s += \r\n网页正文部分左+ windowscreenLeft;

s += \r\n屏幕分辨率的高+ windowscreenheight;

s += \r\n屏幕分辨率的宽+ windowscreenwidth;

s += \r\n屏幕可用工作区高度+ windowscreenavailHeight;

s += \r\n屏幕可用工作区宽度+ windowscreenavailWidth;

//过滤数字

<input type=text onkeypress=return eventkeyCode>=&&eventkeyCode<=||(thisvalueindexOf()<?eventkeyCode==:false) onpaste=return !clipboardDatagetData(text)match(/\D/) ondragenter=return false>

//特殊用途

<input type=button value=导入收藏夹 onclick=windowexternalImportExportFavorites(true//localhost);>

<input type=button value=导出收藏夹 onclick=windowexternalImportExportFavorites(false//localhost);>

<input type=button value=整理收藏夹 onclick=windowexternalShowBrowserUI(OrganizeFavorites null)>

<input type=button value=语言设置 onclick=windowexternalShowBrowserUI(LanguageDialog null)>

<input type=button value=加入收藏夹 onclick=windowexternalAddFavorite( google)>

<input type=button value=加入到频道 onclick=windowexternaladdChannel()>

<input type=button value=加入到频道 onclick=windowexternalshowBrowserUI(PrivacySettingsnull)>

//不缓存

<META HTTPEQUIV=pragma CONTENT=nocache>

<META HTTPEQUIV=CacheControl CONTENT=nocache mustrevalidate>

<META HTTPEQUIV=expires CONTENT=>

//正则匹配

匹配中文字符的正则表达式 [\ue\ufa]

匹配双字节字符(包括汉字在内)[^\x\xff]

匹配空行的正则表达式\n[\s| ]*\r

匹配HTML标记的正则表达式/<(*)>*<\/\>|<(*) \/>/

匹配首尾空格的正则表达式(^\s*)|(\s*$)(像vbscript那样的trim函数)

匹配Email地址的正则表达式\w+([+]\w+)*@\w+([]\w+)*\\w+([]\w+)*

匹配网址URL的正则表达式//([\w]+\)+[\w]+(/[\w /?%&=]*)?

以下是例子

利用正则表达式限制网页表单里的文本框输入内容

用正则表达式限制只能输入中文onkeyup=value=valuereplace(/[^\uE\uFA]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\uE\uFA]/g))

用正则表达式限制只能输入全角字符 onkeyup=value=valuereplace(/[^\uFF\uFFFF]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\uFF\uFFFF]/g))

用正则表达式限制只能输入数字onkeyup=value=valuereplace(/[^\d]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\d]/g))

用正则表达式限制只能输入数字和英文onkeyup=value=valuereplace(/[\W]/g) onbeforepaste=clipboardDatasetData(textclipboardDatagetData(text)replace(/[^\d]/g))

//消除图像工具栏

<IMG SRC=//mypicturejpg HEIGHT=px WIDTH=px GALLERYIMG=false>

or

<head>

<meta httpequiv=imagetoolbar content=no>

</head>

//无提示关闭

function Close()

{

var ua=navigatoruserAgent

var ie=navigatorappName==Microsoft Internet Explorer?true:false

if(ie)

{

var IEversion=parseFloat(uasubstring(uaindexOf(MSIE )+uaindexOf(;uaindexOf(MSIE ))))

if(IEversion< )

{

var str = <object id=noTipClose classid=clsid:ADBADFFCFAABA>

str += <param name=Command value=Close></object>;

documentbodyinsertAdjacentHTML(beforeEnd str);

documentallnoTipCloseClick();

}

else

{

windowopener =null;

windowclose();

}

}

else

{

windowclose()

}

}

//取得控件得绝对位置()

<script language=JavaScript>

function getoffset(e)

{

var t=eoffsetTop;

var l=eoffsetLeft;

while(e=eoffsetParent)

{

t+=eoffsetTop;

l+=eoffsetLeft;

}

var rec = new Array();

rec[] = t;

rec[] = l;

return rec

}

</script>

//获得控件的绝对位置()

oRect = objgetBoundingClientRect();

oRectleft

oRect

//最小化最大化关闭

<object id=min classid=clsid:ADBADFFCFAABA>

<param name=Command value=Minimize></object>

<object id=max classid=clsid:ADBADFFCFAABA>

<param name=Command value=Maximize></object>

<OBJECT id=close classid=clsid:adbadffcfaaba>

<PARAM NAME=Command value=Close></OBJECT>

<input type=button value=最小化 onclick=minClick()>

<input type=button value=最大化 onclick=maxClick()>

<input type=button value=关闭 onclick=closeClick()>

//光标停在文字最后

<script language=JavaScript>

function cc()

{

var e = eventsrcElement;

var r =ecreateTextRange();

rmoveStart(characterevaluelength);

llapse(true);

rselect();

}

</script>

<input type=text name=text value= onfocus=cc()>

//页面进入和退出的特效

进入页面<meta httpequiv=PageEnter content=revealTrans(duration=x transition=y)>

推出页面<meta httpequiv=PageExit content=revealTrans(duration=x transition=y)>

这个是页面被载入和调出时的一些特效duration表示特效的持续时间以秒为单位transition表示使

用哪种特效取值为:

矩形缩小

矩形扩大

圆形缩小

圆形扩大

下到上刷新

上到下刷新

左到右刷新

右到左刷新

竖百叶窗

横百叶窗

错位横百叶窗

错位竖百叶窗

点扩散

左右到中间刷新

中间到左右刷新

中间到上下

上下到中间

右下到左上

右上到左下

左上到右下

左下到右上

横条

竖条

//网页是否被检索

<meta name=ROBOTS content=属性值>

其中属性值有以下一些:

属性值为all: 文件将被检索且页上链接可被查询

属性值为none: 文件不被检索而且不查询页上的链接

属性值为index: 文件将被检索

属性值为follow: 查询页上的链接

属性值为noindex: 文件不检索但可被查询链接

属性值为nofollow:

//打印分页

<p >page</p>

<p >page</p>

//设置打印

<object id=factory  viewastext

classid=clsid:edebdbffdd

codebase=#Version=

></object>

<input type=button value=页面设置 onclick=factoryprintingPageSetup()>

<input type=button value=打印预览 onclick=factoryprintingPreview()>

<script language=JavaScript>

function windowonload()

{

// advanced features

factoryprintingSetMarginMeasure() // measure margins in inches

factoryprintingSetPageRange(false ) // need pages from to

factoryprintingprinter = HP DeskJet C

pies =

llate = true

factoryprintingpaperSize = A

factoryprintingpaperSource = Manual feed

// basic features

factoryprintingheader = 居左显示&b居中显示&b居右显示页码第&p页/共&P页

factoryprintingfooter = (自定义页脚)

factoryprintingportrait = false

factoryprintingleftMargin =

factoryprintingtopMargin =

factoryprintingrightMargin =

factoryprintingbottomMargin =

}

function Print(frame) {

factoryprintingPrint(true frame) // print with prompt

}

</script>

<input type=button value=打印本页 onclick=factoryprintingPrint(false)>

<input type=button value=页面设置 onclick=factoryprintingPageSetup()>

<input type=button value=打印预览 onclick=factoryprintingPreview()><br>

<a target=_blank>具体使用手册更多信息点这里</a>

//自带的打印预览

WebBrowserExecWB() 打开

WebExecWB() 关闭现在所有的IE窗口并打开一个新窗口

WebExecWB() 保存网页

WebExecWB() 打印

WebExecWB() 打印预览

WebExecWB() 打印页面设置

WebExecWB() 查看页面属性

WebExecWB() 好像是撤销有待确认

WebExecWB() 全选

WebExecWB() 刷新

WebExecWB() 关闭窗体无提示

<style media=print>

Noprint{display:none;}<!用本样式在打印时隐藏非打印项目>

PageNext{pagebreakafter: always;}<!控制分页>

</style>

<object id=WebBrowser width= height= classid=CLSID:FADABCFDA>

</object>

<center class=Noprint >

<input type=button value=打印 onclick=documentallWebBrowserExecWB()>

<input type=button value=直接打印 onclick=documentallWebBrowserExecWB()>

<input type=button value=页面设置 onclick=documentallWebBrowserExecWB()>

</p>

<p> <input type=button value=打印预览 onclick=documentallWebBrowserExecWB()>

</center>

//去掉打印时的页眉页脚

<script language=JavaScript>

var HKEY_RootHKEY_PathHKEY_Key;

HKEY_Root=HKEY_CURRENT_USER;

HKEY_Path=\\Software\\Microsoft\\Internet Explorer\\PageSetup\\;

//设置网页打印的页眉页脚为空

function PageSetup_Null()

{

try

{

var Wsh=new ActiveXObject(WScriptShell);

HKEY_Key=header;

WshRegWrite(HKEY_Root+HKEY_Path+HKEY_Key);

HKEY_Key=footer;

WshRegWrite(HKEY_Root+HKEY_Path+HKEY_Key);

}

catch(e){}

}

//设置网页打印的页眉页脚为默认值

function PageSetup_Default()

{

try

{

var Wsh=new ActiveXObject(WScriptShell);

HKEY_Key=header;

WshRegWrite(HKEY_Root+HKEY_Path+HKEY_Key&w&b页码&p/&P);

HKEY_Key=footer;

WshRegWrite(HKEY_Root+HKEY_Path+HKEY_Key&u&b&d);

}

catch(e){}

}

</script>

<input type=button value=清空页码 onclick=PageSetup_Null()>

<input type=button value=恢复页码 onclick=PageSetup_Default()>

//浏览器验证

function checkBrowser()

{

thisver=navigatorappVersion

thisdom=documentgetElementById?:

thisie=(thisverindexOf(MSIE )> && thisdom)?:;

thisie=(thisverindexOf(MSIE )> && thisdom)?:;

thisie=(documentall && !thisdom)?:;

thisns=(thisdom && parseInt(thisver) >= ) ?:;

thisns=(documentlayers && !thisdom)?:;

thismac=(thisverindexOf(Mac) > ) ?:;

thisope=(navigatoruserAgentindexOf(Opera)>);

thisie=(thisie || thisie || thisie)

thisns=(thisns || thisns)

thisbw=(thisie || thisie || thisie || thisns || thisns || thismac || thisope)

thisnbw=(!thisbw)

return this;

}

//计算内容宽和高

<SCRIPT language=JavaScript>

function test(obj)

{

var range = objcreateTextRange();

alert(内容区宽度: + rangeboundingWidth

+ px\r\n内容区高度: + rangeboundingHeight + px);

}

</SCRIPT>

<BODY>

<Textarea id=txt height=>sdf</textarea><INPUT type=button value=计算内容宽度 onClick=test(txt)>

</BODY>

//无模式的提示框

function modelessAlert(Msg)

{

windowshowModelessDialog(JavaScript:alert(\+escape(Msg)+\);windowclose();status:no;resizable:no;help:no;dialogHeight:height:px;dialogHeight:px;);

}

//屏蔽按键

<HTML>

<head>

<meta httpequiv=ContentType content=text/HTML; charset=gb>

<noscript><meta httpequiv=refresh content=;url=about:noscript></noscript>

<title>屏蔽鼠标右键Ctrl+NShift+FAlt+FFF刷新退格键</title>

</head>

<body>

<script language=JavaScript><!

//屏蔽鼠标右键Ctrl+NShift+FFF刷新退格键

//Author: meizz(梅花雨)

function documentoncontextmenu(){eventreturnValue=false;}//屏蔽鼠标右键

function windowonhelp(){return false} //屏蔽F帮助

function documentonkeydown()

{

if ((windoweventaltKey)&&

((windoweventkeyCode==)|| //屏蔽 Alt+ 方向键 ←

(windoweventkeyCode==))) //屏蔽 Alt+ 方向键 →

{

alert(不准你使用ALT+方向键前进或后退网页!);

eventreturnValue=false;

}

/* 注这还不是真正地屏蔽 Alt+ 方向键

因为 Alt+ 方向键弹出警告框时按住 Alt 键不放

用鼠标点掉警告框这种屏蔽方法就失效了以后若

有哪位高手有真正屏蔽 Alt 键的方法请告知*/

if ((eventkeyCode==) || //屏蔽退格删除键

(eventkeyCode==)|| //屏蔽 F 刷新键

(eventctrlKey && eventkeyCode==)){ //Ctrl + R

eventkeyCode=;

eventreturnValue=false;

}

if (eventkeyCode==){eventkeyCode=;eventreturnValue=false;} //屏蔽F

if (eventctrlKey && eventkeyCode==) eventreturnValue=false; //屏蔽 Ctrl+n

if (eventshiftKey && eventkeyCode==)eventreturnValue=false; //屏蔽 shift+F

if (windoweventsrcElementtagName == A && windoweventshiftKey)

windoweventreturnValue = false; //屏蔽 shift 加鼠标左键新开一网页

if ((windoweventaltKey)&&(windoweventkeyCode==)) //屏蔽Alt+F

{

windowshowModelessDialog(about:blankdialogWidth:px;dialogheight:px);

return false;

}

}

</script>

屏蔽鼠标右键Ctrl+NShift+FAlt+FFF刷新退格键

</body>

</HTML>

//屏蔽打印

<style>

@media print{

* {display:none}

}

</style>

//移动的图层拖动

<span style=position:absolute;width:;height:;background:red onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span>

<script language=JavaScript>

var Obj;

function MouseDown(obj)

{

Obj=obj;

ObjsetCapture();

Objl=eventxObjstylepixelLeft;

Objt=eventyObjstylepixelTop;

}

function MouseMove()

{

if(Obj!=null)

{

Objstyleleft = eventxObjl;

Objstyletop = eventyObjt;

}

}

function MouseUp()

{

if(Obj!=null)

{

ObjreleaseCapture();

Obj=null;

}

}

</script>

<div id=myDiv src=//LOGOgif ondrag=doDrag(); onmouseover=thisstylecursor=hand  onmousedown=doMouseDown();>

<a # onclick=return false><h>wlecome</h></a>

</div>

<script language=JavaScript type=text/JavaScript>

var orgMouseX;

var orgMouseY;

var orgObjX;

var orgObjY;

function doDrag()

{

var myObject=documentallmyDiv;

var x=eventclientX;

var y=eventclientY;

myObjectstyleleft=x(orgMouseXorgObjX);

myObjectstyletop=y(orgMouseYorgObjY);

}

function doMouseDown()

{

orgMouseX=eventclientX;

orgMouseY=eventclientY;

orgObjX=parseInt(documentallmyDivstyleleft);

orgObjY=parseInt(documentallmyDivstyletop);

}

</script>

//文档状态改变

<iframe src=//aHTML id=f name=f scrolling=no frameborder= marginwidth= marginheight=></iframe>

<script>

var doc=windowframes[f]document;

function s(){

if (docreadyState==complete){

documentallfstyleheight=docbodyscrollHeight

documentallfstylewidth=docbodyscrollWidth

}

}

doconreadystatechange=s

</script>

//刷新后不变的文本框

<HTML>

<HEAD>

<META NAME=save CONTENT=history>

<STYLE>

sHistory {behavior:url(#default#savehistory);}

</STYLE>

</HEAD>

<BODY>

<INPUT class=sHistory type=text id=oPersistInput>

</BODY>

</HTML>

//访问剪贴板

()拖拽访问

eventdataTransfersetData(URL oImagesrc);

sImageURL = eventdataTransfergetData(URL)

()普通访问

windowclipboardDatasetData(TextoSourceinnerText);

windowclipboardDatagetData(Text);

//操作COOKIE

function SetCookie(sName sValue)

{

okie = sName + = + escape(sValue) + ; ;

}

function GetCookie(sName)

{

var aCookie = okiesplit(; );

for (var i=; i < aCookielength; i++)

{

var aCrumb = aCookie[i]split(=);

if (sName == aCrumb[])

return unescape(aCrumb[]);

}

}

function DelCookie(sName)

{

okie = sName + = + escape(sValue) + ; expires=Fri Dec :: GMT;;

}

//setTimeout增加参数

<script>

var _st = windowsetTimeout;

windowsetTimeout = function(fRef mDelay) {

if(typeof fRef == function){

var argu = Arrayprototypeslicecall(arguments);

var f = (function(){ fRefapply(null argu); });

return _st(f mDelay);

}

return _st(fRefmDelay);

}

function test(x){

alert(x);

}

windowsetTimeout(testfason);

</script>

//自定义的applycall

Functionprototypeapply = function (obj argu) {

if (obj) nstructorprototype_caller = this;

var argus = new Array();

for (var i=;i<argulength;i++)

argus[i] = argu[ + i + ];

var r;

eval(r = + (obj ? (obj_caller( + argusjoin() + );) : (this( + argusjoin() + );)));

return r;

};

Functionprototypecall = function (obj) {

var argu = new Array();

for (var i=;i<argumentslength;i++)

argu[i] = arguments[i];

return thisapply(obj argu);

};

//下载文件

function DownURL(strRemoteURLstrLocalURL)

{

try

{

var XMLHTTP=new ActiveXObject(MicrosoftXMLHTTP);

XMLHTTPopen(GetstrRemoteURLfalse);

XMLHTTPsend();

var adodbStream=new ActiveXObject(ADODBStream);

adodbStreamType=;//=adTypeBinary

adodbStreamOpen();

adodbStreamwrite(XMLHTTPresponseBody);

adodbStreamSaveToFile(strLocalURL);

adodbStreamClose();

adodbStream=null;

XMLHTTP=null;

}

catch(e)

{

nfirm(下载URL出错!);

}

//nfirm(下载完成);

}

//检验连接是否有效

function getXML(URL)

{

var XMLhttp = new ActiveXObject(microsoftXMLhttp);

XMLhttpOpen(GETURL false);

try

{

XMLhttpSend();

}

catch(e){}

finally

{

var result = XMLhttpresponseText;

if(result)

{

if(XMLhttpStatus==)

{

return(true);

}

else

{

return(false);

}

}

else

{

return(false);

}

}

}

//POST代替FORM

<SCRIPT language=VBScript>

Function URLEncoding(vstrIn)

strReturn =

For i = To Len(vstrIn)

ThisChr = Mid(vStrIni)

If Abs(Asc(ThisChr)) < &HFF Then

strReturn = strReturn & ThisChr

Else

innerCode = Asc(ThisChr)

If innerCode < Then

innerCode = innerCode + &H

End If

Hight = (innerCode And &HFF)\ &HFF

Low = innerCode And &HFF

strReturn = strReturn & % & Hex(Hight) & % & Hex(Low)

End If

Next

URLEncoding = strReturn

End Function

Function bytesBSTR(vIn)

strReturn =

For i = To LenB(vIn)

ThisCharCode = AscB(MidB(vIni))

If ThisCharCode < &H Then

strReturn = strReturn & Chr(ThisCharCode)

Else

NextCharCode = AscB(MidB(vIni+))

strReturn = strReturn & Chr(CLng(ThisCharCode) * &H + CInt(NextCharCode))

i = i +

End If

Next

bytesBSTR = strReturn

End Function

dim strAoReq

strA = URLEncoding(submit=Submit&text=中文)

set oReq = CreateObject(MSXMLXMLHTTP)

oReqopen POSTfalse

oReqsetRequestHeader ContentLengthLen(strA)

oReqsetRequestHeader CONTENTTYPEapplication/xwwwformurlencoded

oReqsend strA

msgbox bytesBSTR(oReqresponseBody)

</SCRIPT>

//readyState是XMLhttp返回数据的进度=载入中=未初始化=已载入=运行中=完成

//组件是否安装

isComponentInstalled({BABAECDDBFFAA} componentID))

//检查网页是否存在

function CheckURL(URL)

{

var XMLhttp = new ActiveXObject(MicrosoftXMLHTTP);

XMLhttpOpen(GETURL false);

try

{

XMLhttpSend();

var result = XMLhttpstatus;

}

catch(e) {return(false); }

if(result==)

{

return true;

}

XMLhttp = null;

return false;

}

//连接数据库

<script language=JavaScript>

//用 JavaScript 写服务器端连接数据库的代码示例

var conn = new ActiveXObject(ADODBConnection);

connOpen(Provider=SQLOLEDB; Data Source=localhost; User ID=sa;

+Password=; Initial Catalog=pubs);

var rs = new ActiveXObject(ADODBRecordset);

var sql=select * from authors;

rsopen(sql conn);

sHTML = <table width=% border=>;

sHTML +=<tr bgcolor=#fff><td>au_id</td><td>au_lname</td><td>au_fname</td><td>phone</td><td>address</td><td> city</td><td>state</td><td>zip</td></tr>;

while(!rsEOF)

{

sHTML += <tr><td> + rs(au_id) + </td><td> + rs(au_lname) + </td><td> + rs(au_fname) + </td><td> + rs(phone) + </td><td> + rs(address) + </td><td> + rs(city) + </td><td> + rs(state) + </td><td> + rs(zip) + </td></tr>;

rsmoveNext;

}

sHTML += </table>;

documentwrite(sHTML);

rsclose();

rs = null;

connclose();

conn = null;

</script>

//使用数据岛

<HTML>

<body>

srno<input type=text datasrc=//#XMLdate DataFLD=srno size=><BR>

times<input type=text datasrc=//#XMLdate DataFLD=times size=><BR>

<input id=first TYPE=button value=<<第一条记录 onclick=XMLdaterecordsetmoveFirst()>

<input id=prev TYPE=button value=<上一条记录 onclick=XMLdaterecordsetmovePrevious()>

<input id=next TYPE=button value=下一条记录> onclick=XMLdaterecordsetmoveNext()>

<input id=last TYPE=button value=最后一条记录>> onclick=XMLdaterecordsetmoveLast()>

<input id=Add TYPE=button value=添加新记录 onclick=XMLdaterecordsetaddNew()>

<XML ID=XMLdate>

<infolist>

<info ><srno></srno><times>null</times></info>

<info ><srno></srno><times>秒</times></info>

</infolist>

</XML>

</body>

</HTML>

//获得参数

<body>

<a JavaScript:locationhref=locationhref + ?a=&b=>search</a>

<script language=JavaScript>

<!

var a = locationsearchsubstr();

if(alength>)

{

var re = /([^&]*?)\=([^&]*)/g

var s = amatch(re);

for(var i= ;i<slength;i++)

{

alert(s[i]);

alert(s[i]split(=)[]);

}

}

//>

</script>

</body>

//可编辑SELECT

<input type=text name=re_name ><span ><select name=r  onChange=documentallre_namevalue=thisvalue;>

<option value=><option>

<option value=></option>

<option value=></option>

</select>

</span>

               

上一篇:JavaScript中面向对象技术的模拟

下一篇:JAVASCRIPT加密解密终级指南