天天看点

[转] javascript小技巧

?

  • 浜?浠舵?瀵硅薄

    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=="TD

    document.elementFromPoint(event.x,event.y).appendChild(ms)?

  • 绐?浣??剧??

    document.images[绱㈠?]

  • 绐?浣?浜?浠剁?瀹?

    document.慰nm慰used慰wn=scrollwindow;

  • ??绱?

    document.绐?浣?.elements[绱㈠?]

  • 瀵硅薄缁?瀹?浜?浠?

    document.all.xxx.detachEvent('onclick',a);

  • ??浠舵?扮??

    navigator.plugins

  • ??????绫诲??

    typeof($js_libpath) == "undefined"

  • 涓???妗?

    涓???妗?.options[绱㈠?]

    涓???妗?.options.length

  • ?ユ?惧?硅薄

    document.getElementsByName("r1");

    document.getElementById(id);

  • 瀹???

    timer=setInterval('scrollwindow()',delay);

    clearInterval(timer);

  • UNCODE缂???

    escape() ,unescape

  • ?跺?硅薄

    obj.parentElement(dhtml)

    obj.parentNode(dom)

  • 浜ゆ?㈣〃??琛?

    TableID.moveRow(2,1)

  • ?挎??SS

    document.all.csss.href = "a.css";

  • 骞舵???剧ず

    display:inline

  • ????????

    hidefocus=true

  • ?规??瀹藉害?㈣?

    style="word-break:break-all"

  • ???ㄥ?锋??

    <meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">

  • 绠?????浠?

    <a? href="mailto:[email?protected]?subject=ccc&body=xxxyyy">?

  • 蹇???杞??颁?缃?

    obj.scrollIntoView(true)

  • ??

    <a name="first">

    <a href="#first" target="_blank" rel="external nofollow" >anchors</a>

  • 缃?椤典???????

    location.search();

  • ??缂?杈?

    obj.contenteditable=true

  • ?ц??????戒护

    obj.execCommand

  • ??瀛???瀛?绗?

    /[^/x00-/xff]/

    姹?瀛?

    /[/u4e00-/u9fa5]/

  • 璁╄?辨??瀛?绗?覆瓒??鸿〃?煎?藉害???ㄦ?㈣?

    word-wrap: break-word; word-break: break-all;

  • ????????

    <IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>

  • ?峰?style??瀹?

    obj.style.cssText

  • HTML??绛?

    document.documentElement.innerHTML

  • 绗?涓?涓?style??绛?

    document.styleSheets[0]

  • style??绛鹃????绗?涓?涓??峰?

    document.styleSheets[0].rules[0]

  • ?叉?㈢?瑰?荤┖?炬?ユ?讹?椤甸?㈠?寰???缃??伴〉棣?绔???

    <a href="javascript:function()" target="_blank" rel="external nofollow" >word</a>

  • 涓?涓?缃?椤垫?

    asp:

    request.servervariables("HTTP_REFERER")

    javascript:

    document.referrer

  • ???惧??瀛?

    CollectGarbage();

  • 绂?姝㈠?抽??

    document.oncontextmenu = function() { return false;}

  • 绂?姝??瀛?

    <noscript><iframe src="*.htm"></iframe></noscript>

  • 绂?姝㈤????<body?慰nc慰ntextmenu="return?false"?慰ndragstart="return?false"?onselectstart?="return?false"?慰nselect="document.selection.empty()"?慰nc慰py="document.selection.empty()"?onbeforecopy="return?false"慰nm慰useup="document.selection.empty()>?
  • 绂?姝㈢?璐?

    <input type=text 慰npaste="return false">

  • ?板?????炬??

    <link rel="Shortcut Icon" href="favicon.ico" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >

    favicon.ico ??瀛???濂戒???16*16??16???捐??????褰??圭??褰?涓?

  • ?惰?????炬??

    <link rel="Bookmark" href="favicon.ico" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" >

  • ?ョ??婧???

    <input type=button value=?ョ??缃?椤垫?浠g?? 慰nclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">

  • ?抽??杈??ユ?

    <input style="ime-mode:disabled">

  • ???ㄥ?ㄩ??

    <input type=text name=text1 value="123" 慰nf慰cus="this.select()">

  • ENTER????浠ヨ?╁????绉诲?颁?涓?涓?杈??ユ?

    <input 慰nkeyd慰wn="if(event.keyCode==13)event.keyCode=9">

  • ????妗???榛?璁ゅ??

    <input type=text value="123" 慰nf慰cus="alert(this.defaultValue)">

  • title?㈣?

    obj.title = "123 sdfs "

  • ?峰??堕?存??浠h〃??寰?绉?

    var n1 = new Date("2004-10-10".replace(/-/g, "//")).getTime()

  • 绐??f?????抽??

    win.closed

  • checkbox??骞?

    <input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>

  • ?峰????涓???瀹?

    document.selection.createRange().duplicate().text

  • ???ㄥ????????

    <input? type=text? autocomplete=on>??寮?璇ュ???铰?

    <input? type=text? autocomplete=off>?抽??璇ュ???铰???

  • 绐??f??澶у??

    <body 慰nl慰ad="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">

  • ???抽??????IE

    window.open("aa.htm", "meizz", "fullscreen=7");

  • 缁?涓?缂???/瑙g??

    alert(decodeURIComponent(encodeURIComponent("http://浣?濂?com?as= hehe")))

    encodeURIComponent瀵?:"??"/"??";" ?? "?"涔?缂???

  • 琛ㄦ?艰???绀?

    <tr 慰nm慰use慰ver="this.bgColor='#f0f0f0'" 慰nm慰use慰ut="this.bgColor='#ffffff'">

    //??绉?灏哄??

    s??+=?? "/r/n缃?椤靛??瑙??哄??瀹斤?"+??document.body.clientWidth;??

    s??+=??"/r/n缃?椤靛??瑙??哄??楂?锛?"+??document.body.clientHeight;??

    s??+=??"/r/n缃?椤靛??瑙??哄??楂?锛?"+??document.body.offsetWeight??+"??(????杈圭嚎??瀹?";??

    s??+=??"/r/n缃?椤靛??瑙??哄??楂?锛?"+??document.body.offsetHeight??+"??(????杈圭嚎??瀹?";??

    s??+=??"/r/n缃?椤垫?f???ㄦ??瀹斤?"+??document.body.scrollWidth;??

    s??+=??"/r/n缃?椤垫?f???ㄦ??楂?锛?"+??document.body.scrollHeight;??

    s??+=??"/r/n缃?椤佃??峰?荤??楂?锛?"+??document.body.scrollTop;??

    s??+=??"/r/n缃?椤佃??峰?荤??宸??"+??document.body.scrollLeft;??

    s??+=??"/r/n缃?椤垫?f???ㄥ??涓?锛?"+??window.screenTop;??

    s??+=??"/r/n缃?椤垫?f???ㄥ??宸??"+??window.screenLeft;??

    s??+=??"/r/n灞?骞???杈ㄧ????楂?锛?"+??window.screen.height;??

    s??+=??"/r/n灞?骞???杈ㄧ????瀹斤?"+??window.screen.width;??

    s??+=??"/r/n灞?骞????ㄥ伐浣??洪??搴??"+??window.screen.availHeight;??

    s??+=??"/r/n灞?骞????ㄥ伐浣??哄?藉害锛?"+??window.screen.availWidth;??

//杩?婊ゆ?板??

?

//?规???ㄩ??

?

//涓?缂?瀛?

?

//姝e???归??

?

?归??涓???瀛?绗???姝e??琛ㄨ揪寮?锛??[/u4e00-/u9fa5]

?归????瀛???瀛?绗?????姹?瀛??ㄥ??)锛?[^/x00-/xff]

?归??绌鸿???姝e??琛ㄨ揪寮?锛?/n[/s|?]*/r

?归??HTML??璁扮??姝e??琛ㄨ揪寮?锛?/<(.*)>.*<///1>|<(.*)?//>/?

?归??棣?灏剧┖?肩??姝e??琛ㄨ揪寮?锛?(^/s*)|(/s*$)锛???vbscript?f?风??trim?芥?帮?

?归??Email?板????姝e??琛ㄨ揪寮?锛?/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*

?归??缃???URL??姝e??琛ㄨ揪寮?锛?http: //([/w-]+/.)+[/w-]+(/[/w-?./?%&=]*)?

浠ヤ???渚?瀛?锛?

?╃?ㄦ?e??琛ㄨ揪寮????剁?椤佃〃??????????妗?杈??ュ??瀹癸?

?ㄦ?e??琛ㄨ揪寮????跺???借??ヤ腑??锛?慰nkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')"?onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"

1.?ㄦ?e??琛ㄨ揪寮????跺???借??ュ?ㄨ?瀛?绗???慰nkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'')"?onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))"

2.?ㄦ?e??琛ㄨ揪寮????跺???借??ユ?板??锛?慰nkeyup="value=value.replace(/[^/d]/g,'')?"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"

3.?ㄦ?e??琛ㄨ揪寮????跺???借??ユ?板?????辨??锛?慰nkeyup="value=value.replace(/[/W]/g,'')?"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"

//娑??ゅ?惧??宸ュ?锋??

?

?

<IMG?SRC="mypicture.jpg"?HEIGHT="100px"?WIDTH="100px"?GALLERYIMG="false">?

or

<head>

<meta?http-equiv="imagetoolbar"?content="no">

</head>

//????绀哄?抽??

function?Close()

{

?var?ua=navigator.userAgent

?var?ie=navigator.appName=="Microsoft?Internet?Explorer"?true:false

?if(ie)

?{

??????var?IEversion=parseFloat(ua.substring(ua.indexOf("MSIE?")+5,ua.indexOf(";",ua.indexOf("MSIE?"))))

??if(IEversion<?5.5)

??{

???var?str??=?'<object?id=noTipClose?classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'

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

???????document.body.insertAdjacentHTML("beforeEnd",?str);

???????document.all.noTipClose.Click();

??}

??????else

??{

???????window.opener?=null;

???????window.close();

??????}

???}

?else

?{

??window.close()

???}

}

//??寰??т欢寰?缁?瀵逛?缃?(1)

<script?language= "javascript">?

function?getoffset(e)

{?

?var?t=e.offsetTop;?

?var?l=e.offsetLeft;?

?while(e=e.offsetParent)

?{?

??t+=e.offsetTop;?

??l+=e.offsetLeft;?

?}?

?var?rec?=?new?Array(1);

?rec[0]??=?t;

?rec[1]?=?l;

?return?rec

}?

</script>

//?峰??т欢??缁?瀵逛?缃?(2)

oRect?=?obj.getBoundingClientRect();

oRect.left

oRect.

//??灏???,??澶у??,?抽??

?

?

//???????ㄦ??瀛?????

?

<script?language= "javascript">

function?cc()

{

?var?e?=?event.srcElement;

?var?r?=e.createTextRange();

?r.moveStart('character',e.value.length);

?r.collapse(true);

?r.select();

}

</script>

<input?type=text?name=text1?value="123"?慰nf慰cus="cc()">

//椤甸?㈣??ュ?????虹???规??

杩??ラ〉??lt;meta?http-equiv= "Page-Enter"?content="revealTrans(duration=x,?transition=y)">

?ㄥ?洪〉??lt;meta?http-equiv="Page-Exit"?content="revealTrans(duration=x,?transition=y)">?

杩?涓???椤甸?㈣?杞藉?ュ??璋??烘?剁??涓?浜??规????duration琛ㄧず?规??????缁??堕?达?浠ョ?涓哄??浣???transition琛ㄧず浣?

?ㄥ??绉??规??锛????间负1-23:

????0??╁舰缂╁??

????1??╁舰?╁ぇ?

????2???褰㈢缉灏?

????3???褰㈡?╁ぇ?

????4?涓??颁??锋?奥?

????5?涓??颁??锋??

????6?宸??板?冲?锋?奥?

????7??冲?板乏?锋?奥?

????8?绔??惧?剁??

????9?妯??惧?剁???

????10???浣?妯??惧?剁???

????11???浣?绔??惧?剁??

????12??规?╂?B?

????13?宸??冲?颁腑?村?锋?奥?

????14?涓??村?板乏?冲?锋??

????15?涓??村?颁?涓?

????16?涓?涓??颁腑?绰?

????17??充??板乏涓?

????18??充??板乏涓??

????19?宸???板?充??

????20?宸???板?充?

????21?妯??÷?

????22?绔??÷?

????23?

//缃?椤垫?????妫?绱?

?

//???板??椤?

?

//璁剧疆????

<object?id= "factory"?style="display:none"?viewastext

??classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"

??codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"

></object>

<input?type=button?value=椤甸?㈣?剧疆?慰nclick="factory.printing.PageSetup()">

<input?type=button?value=???伴?瑙??慰nclick="factory.printing.Preview()">

?

<script?language=javascript>

function?window.onload()

{

???//?--?advanced?features

???factory.printing.SetMarginMeasure(2)?//?measure?margins?in?inches

???factory.printing.SetPageRange(false,?1,?3)?//?need?pages?from?1?to?3

???factory.printing.printer?=?"HP?DeskJet?870C"

???factory.printing.copies?=?2

???factory.printing.collate?=?true

???factory.printing.paperSize?=?"A4"

???factory.printing.paperSource?=?"Manual?feed"

???//?--?basic?features

???factory.printing.header?=?"灞?宸??剧ず&b灞?涓??剧ず&b灞??虫?剧ず椤电??锛?绗?&p椤???amp;P椤?

???factory.printing.footer?=?"锛???瀹?涔?椤佃??锛?"

???factory.printing.portrait?=?false

???factory.printing.leftMargin?=?0.75

???factory.printing.topMargin?=?1.5

???factory.printing.rightMargin?=?0.75

???factory.printing.bottomMargin?=?1.5

}

function?Print(frame)?{

??factory.printing.Print(true,?frame)?//?print?with?prompt

}

</script>

<input?type=button?value="???版??椤??慰nclick="factory.printing.Print(false)">

<input?type=button?value="椤甸?㈣?剧疆"?慰nclick="factory.printing.PageSetup()">

<input?type=button?value="???伴?瑙?"?慰nclick="factory.printing.Preview()"><br>

<a?href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static"??target=_blank>?蜂?浣跨?ㄦ????锛??村?淇℃??锛??硅???</a>

?

//??甯??????伴?瑙?

WebBrowser.ExecWB(1,1)???寮??

Web.ExecWB(2,1)??抽???板?ㄦ??????IE绐??o?骞舵??寮?涓?涓??扮???B?

Web.ExecWB(4,1)?淇?瀛?缃?椤德?

Web.ExecWB(6,1)????奥?

Web.ExecWB(7,1)????伴?瑙??

Web.ExecWB(8,1)????伴〉?㈣?剧疆?

Web.ExecWB(10,1)??ョ??椤甸?㈠????

Web.ExecWB(15,1)?濂藉?????ら??锛???寰?纭?璁ぢ?

Web.ExecWB(17,1)??ㄩ???

Web.ExecWB(22,1)??锋?奥?

Web.ExecWB(45,1)??抽??绐?浣?????绀郝?

<style?media=print>?

.Noprint{display:none;}<!--?ㄦ???峰??ㄦ???版?堕?????????伴」??-->?

.PageNext{page-break-after:?always;}<!--?у?跺??椤?->?

</style>?

<object??id= "WebBrowser"??width=0??height=0??classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">????

</object>????

?

<center?class="Noprint"?>

<input?type=button?value=???奥?慰nclick=document.all.WebBrowser.ExecWB(6,1)>?

<input?type=button?value=?存?ユ???奥?慰nclick=document.all.WebBrowser.ExecWB(6,6)>?

<input?type=button?value=椤甸?㈣?剧疆?慰nclick=document.all.WebBrowser.ExecWB(8,1)>?

</p>?

<p>?<input?type=button?value=???伴?瑙??慰nclick=document.all.WebBrowser.ExecWB(7,1)>?

</center>

//?绘?????版?剁??椤电??椤佃??

<script??language= "JavaScript">??

var?HKEY_Root,HKEY_Path,HKEY_Key;

HKEY_Root="HKEY_CURRENT_USER";

HKEY_Path="//Software//Microsoft//Internet?Explorer//PageSetup//";

//璁剧疆缃?椤垫???扮??椤电??椤佃??涓虹┖

function?PageSetup_Null()

{

?try

?{

?????????var?Wsh=new?ActiveXObject("WScript.Shell");

??HKEY_Key="header";

??Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");

??HKEY_Key="footer";

??Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");

?}

?catch(e){}

}

//璁剧疆缃?椤垫???扮??椤电??椤佃??涓洪?璁ゅ??

function??PageSetup_Default()

{??

?try

?{

??var?Wsh=new?ActiveXObject("WScript.Shell");

??HKEY_Key="header";

??Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b椤电??,&p/&P");

??HKEY_Key="footer";

??Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");

?}

?catch(e){}

}

</script>

<input?type="button"?value="娓?绌洪〉??"?慰nclick=PageSetup_Null()>

<input?type="button"?value="?㈠?椤电??"?慰nclick=PageSetup_Default()>

//娴?瑙??ㄩ??璇?

function?checkBrowser()

{?

???this.ver=navigator.appVersion?

???this.dom=document.getElementById?1:0?

???this.ie6=(this.ver.indexOf("MSIE?6")>-1?&&?this.dom)?1:0;?

???this.ie5=(this.ver.indexOf("MSIE?5")>-1?&&?this.dom)?1:0;?

???this.ie4=(document.all?&&?!this.dom)?1:0;?

???this.ns5=(this.dom?&&?parseInt(this.ver)?>=?5)??1:0;?

???this.ns4=(document.layers?&&?!this.dom)?1:0;?

???this.mac=(this.ver.indexOf('Mac')?>?-1)??1:0;?

???this.ope=(navigator.userAgent.indexOf('Opera')>-1);?

???this.ie=(this.ie6?||?this.ie5?||?this.ie4)?

???this.ns=(this.ns4?||?this.ns5)?

???this.bw=(this.ie6?||?this.ie5?||?this.ie4?||?this.ns5?||?this.ns4?||?this.mac?||?this.ope)?

???this.nbw=(!this.bw)?

???return?this;

}

//璁$????瀹瑰?藉??楂?

?

?

<SCRIPT??language= "javascript">??

function??test(obj)??

{??

???????var??range??=??obj.createTextRange();??

???????alert("??瀹瑰?哄?藉害:??"??+??range.boundingWidth????

?????????????????????????????????????????????????+??"px/r/n??瀹瑰?洪??搴???"??+??range.boundingHeight??+??"px");??

?????????????

}??

</SCRIPT>??

<BODY>??

<Textarea?id="txt"?height="150">sdf</textarea><INPUT??type="button"??value="璁$????瀹瑰?藉害"??onClick="test(txt)">??

</BODY>

//??妯″?????绀烘?

?

?

function?modelessAlert(Msg)

{

???window.showModelessDialog("javascript:alert(/""+escape(Msg)+"/");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;");

}

?

//灞??芥????

?

<html>

<head>

??<meta?http-equiv= "Content-Type"?content="text/html;?charset=gb2312">

??<noscript><meta?http-equiv="refresh"?content="0;url=about:noscript"></noscript>

??<title>灞??介????抽????Ctrl+N??Shift+F10??Alt+F4??F11??F5?锋?般?????奸??</title>

</head>

<body>

<script?language="Javascript"><!--

??//灞??介????抽????Ctrl+N??Shift+F10??F11??F5?锋?般?????奸??

??//Author:?meizz(姊??遍???2002-6-18

function?document.oncontextmenu(){event.returnValue=false;}//灞??介????抽??

function?window.onhelp(){return?false}?//灞???1甯???

function?document.onkeydown()

{

??if?((window.event.altKey)&&

??????((window.event.keyCode==37)||???//灞??铰?Alt+??瑰???????

???????(window.event.keyCode==39)))???//灞??铰?Alt+??瑰???????

??{

?????alert("涓???浣?浣跨??LT+?瑰??????杩???????缃?椤碉?");

?????event.returnValue=false;

??}

?????

??if?((event.keyCode==8)??||?????????????????//灞??介???煎???ら??

??????(event.keyCode==116)||?????????????????//灞??铰?F5??锋?伴??

??????(event.ctrlKey?&&?event.keyCode==82)){?//Ctrl?+?R

?????event.keyCode=0;

?????event.returnValue=false;

?????}

??if?(event.keyCode==122){event.keyCode=0;event.returnValue=false;}??//灞???11

??if?(event.ctrlKey?&&?event.keyCode==78)?event.returnValue=false;???//灞??铰?Ctrl+n

??if?(event.shiftKey?&&?event.keyCode==121)event.returnValue=false;??//灞??铰?shift+F10

??if?(window.event.srcElement.tagName?==?"A"?&&?window.event.shiftKey)?

??????window.event.returnValue?=?false;?????????????//灞??铰?shift???榧???宸????板?涓?缃?椤?

??if?((window.event.altKey)&&(window.event.keyCode==115))?????????????//灞???lt+F4

??{

??????window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");

??????return?false;

??}

}

</script>

灞??介????抽????Ctrl+N??Shift+F10??Alt+F4??F11??F5?锋?般?????奸??

</body>

</html>

//灞??芥????

<style>

@media print{

* {display:none}

}

</style>

//绉诲?ㄧ???惧?锛?????

1.<span?style='position:absolute;width:200;height:200;background:red'?慰nm慰used慰wn=MouseDown( this)?慰nm慰usem慰ve=MouseMove()?慰nm慰useup=MouseUp()>meizz</span>

<script?language=javascript>

var?Obj;

function?MouseDown(obj)

{

??Obj=obj;

??Obj.setCapture();

??Obj.l=event.x-Obj.style.pixelLeft;

??Obj.t=event.y-Obj.style.pixelTop;

}

function?MouseMove()

{

??if(Obj!=null)

??{

????Obj.style.left?=?event.x-Obj.l;

????Obj.style.top?=?event.y-Obj.t;

??}

}

function?MouseUp()

{

??if(Obj!=null)

??{

????Obj.releaseCapture();

????Obj=null;

??}

}

</script>

2.

<div?id="myDiv"?src="logo.gif"?慰ndrag="doDrag();"?慰nm慰use慰ver="this.style.cursor='hand'"?style="position:absolute;left=100;top=100;"?慰nm慰used慰wn="doMouseDown();">

<a?href="#"?慰nclick="return?false"><h1>wlecome</h1></a>

</div>

<script?language="JavaScript"?type="text/javascript">

var?orgMouseX;

var?orgMouseY;

var?orgObjX;

var?orgObjY;

function?doDrag()

{

var?myObject=document.all.myDiv;

var?x=event.clientX;

var?y=event.clientY;

myObject.style.left=x-(orgMouseX-orgObjX);

myObject.style.top=y-(orgMouseY-orgObjY);

?

}

function?doMouseDown()

{

orgMouseX=event.clientX;

orgMouseY=event.clientY;

orgObjX=parseInt(document.all.myDiv.style.left);

orgObjY=parseInt(document.all.myDiv.style.top);

}

</script>

?

//??妗g?舵???瑰??

<iframe?src= "a.html"?id="f"?name="f"?scrolling="no"?framef"].document;

function?s(){

?if?(doc.readyState=="complete"){

??document.all.f.style.height=doc.body.scrollHeight

??document.all.f.style.width=doc.body.scrollWidth

?}

}

doc.onreadystatechange=s

</script>

//?锋?板??涓?????????妗?

?

//璁块????璐存??

?

//??浣?COOKIE

function?SetCookie(sName,?sValue)

{

?document.cookie?=?sName?+?"="?+?escape(sValue)?+?";?";

}

function?GetCookie(sName)

{

?var?aCookie?=?document.cookie.split(";?");

?for?(var?i=0;?i?<?aCookie.length;?i++)

?{

??

??var?aCrumb?=?aCookie[i].split("=");

??if?(sName?==?aCrumb[0])?

??return?unescape(aCrumb[1]);

?}

?

}

function?DelCookie(sName)

{

document.cookie?=?sName?+?"="?+?escape(sValue)?+?";?expires=Fri,?31?Dec?1999?23:59:59?GMT;";

}

//setTimeout澧???????

<script>

var?_st?=?window.setTimeout;

window.setTimeout?=?function(fRef,?mDelay)?{

?if(typeof?fRef?==?'function'){

??var?argu?=?Array.prototype.slice.call(arguments,2);

??var?f?=?(function(){?fRef.apply(null,?argu);?});

??return?_st(f,?mDelay);

?}

?return?_st(fRef,mDelay);

}

function?test(x){

?alert(x);

}

window.setTimeout(test,1000,'fason');

</script>

//??瀹?涔???apply,call

Function.prototype.apply?=? function?(obj,?argu)?{

?if?(obj)?obj.constructor.prototype._caller?=?this;?

?var?argus?=?new?Array();

?for?(var?i=0;i<argu.length;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<arguments.length;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("涓?杞?RL?洪??!");

?}

?//window.confirm("涓?杞藉????.");

}

//妫?楠?杩??ユ????????

?

//缁?浠舵??????瑁?

isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "componentID"))

//妫??ョ?椤垫????????

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;

}

//杩??ユ?版??搴?

<script?language= "javascript">

??//???JavaScript??????″?ㄧ??杩??ユ?版??搴???浠g??绀轰?

??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?=?"<table?width='100%'?;

?shtml?+="<tr?bgcolor='#f4f4f4'><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(!rs.EOF)

??{

?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>";

?rs.moveNext;

??}

??shtml?+=?"</table>";

??document.write(shtml);

??rs.close();?

??rs?=?null;?

??conn.close();?

??conn?=?null;

</script>

//浣跨?ㄦ?版??宀?

?

?

<html>

<body>

srno锛?<input?type=text?datasrc=#xmldate?DataFLD=srno?size= "76"><BR>

times锛?<input?type=text?datasrc=#xmldate?DataFLD=times?size="76"><BR>

<input?id="first"?TYPE=button?value="<<??绗?涓??¤?板?"?慰nclick="xmldate.recordset.moveFirst()">

<input?id="prev"?TYPE=button?value="<涓?涓??¤?板?"?慰nclick="xmldate.recordset.movePrevious()">??

<input?id="next"?TYPE=button?value="涓?涓??¤?板?>"?慰nclick="xmldate.recordset.moveNext()">??

<input?id="last"?TYPE=button?value="????涓??¤?板?>>"?慰nclick="xmldate.recordset.moveLast()">???

<input?id="Add"?TYPE=button?value="娣诲???拌?板?"?慰nclick="xmldate.recordset.addNew()">??

<XML?ID="xmldate">

<infolist>

<info?><srno>20041025-01</srno><times>null</times></info>

<info?><srno>20041101-09</srno><times>2004骞?0??1????2??0绉?</times></info>

</infolist>

</XML>

</body>

</html>

//?峰?????

?

?

<body>

<a?href= "javascript:location.href=location.href?+?'?a=1&b=2'">search</a>

<script?language="JavaScript">

<!--

var?a?=?location.search.substr(1);

if(a.length>0)

{

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

?var?s?=?a.match(re);

?for(var?i=?0;i<s.length;i++)

?{

??alert(s[i]);

??alert(s[i].split("=")[1]);

?}

}

//-->

</script>

</body>

//??缂?杈?SELECT

?

?

<input?type=text?name=re_name?style= "width:100px;height:21px;font-size:10pt;"><span?style="width:18px;border:0px?solid?red;"><select?name="r00"?style="margin-left:-100px;width:118px;?background-color:#FFEEEE;"?onChange="document.all.re_name.value=this.value;">

????????????????<option?value="1">11111111<option>

????????????????<option?value="2">222222</option>

????????????????<option?value="3">333333</option>

??????????????</select>

??????????????</span>

//璁剧疆????浣?缃?

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?<=?n?&&?(found?=?txt.findText(str))?!=?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?/n璇疯????杈??ラ〉??腑???抽??瀛???娆℃?ユ?撅?");

??}

?}

?return?false;

}

//涔?

http://www.itpub.net/attachment.php?s=&postid=1894598

http://www.wrclub.net/down/listdown.aspx?id=1341

//??浣?EXECL

<script?language= "javascript">

function?jStartExcel()?{

?var?xls?=?new?ActiveXObject?(?"Excel.Application"?);

?xls.visible?=?true;

?var?newBook?=?xls.Workbooks.Add;

?newBook.Worksheets.Add;

?newBook.Worksheets(1).Activate;

?xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation?=?2;

?xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize?=?5;

?newBook.Worksheets(1).Columns("A").columnwidth=50;

?newBook.Worksheets(1).Columns("A").WrapText?=?true;

?newBook.Worksheets(1).Columns("B").columnwidth=50;

?newBook.Worksheets(1).Columns("B").WrapText?=?true;

?newBook.Worksheets(1).Range("A1:B1000").NumberFormat?=?"0";

?newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment?=?-4131;

?newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15";

?newBook.Worksheets(1).Cells(1,1).value="First?Column,?First?Cell";

?newBook.Worksheets(1).Cells(2,1).value="First?Column,?Second?Cell";

?newBook.Worksheets(1).Cells(1,2).value="Second?Column,?First?Cell";

?newBook.Worksheets(1).Cells(2,2).value="Second?Column,?Second?Cell";

?newBook.Worksheets(1).Name="My?First?WorkSheet";

}

</script>

//??瀹?涔???绀烘??

<a?href= "#"?title="杩?????绀?>tip</a>

<script?Language="JavaScript">

/

</script>

//??寰?innerText

<SCRIPT?LANGUAGE= "JavaScript">

<!--

?var?xmlDoc?=?new?ActiveXObject("Msxml2.DOMDocument.4.0");

?var?currNode;

?xmlDoc.async?=?false;

?xmlDoc.async?=?false;

?xmlDoc.loadXML("<TABLENAME>??????浣?濂戒??夸?????澶ф???????告?绛?????????????????</TABLENAME>");

?currNode?=?xmlDoc.documentElement;

???

??var?s?=?currNode.xml;

??var?r?=?//<([^/>/s]*?)[^/>]*?/>([^/<]*?)/<///1/>/

??var?b?=?s.replace(r,"$2");

??alert(b);

//-->

</SCRIPT>

//mergeAttributes 澶??舵????璇?????绛惧??у?版??瀹???绱???

<SCRIPT>

function?fnMerge(){

oSource.children[1].mergeAttributes(oSource.children[0]);

}

</SCRIPT>

<SPAN?ID=oSource>

<DIV

ID="oDiv"

ATTRIBUTE1="true"

ATTRIBUTE2="true"

慰nclick="alert('click');"

慰nm慰use慰ver="this.style.color='#0000FF';"

慰nm慰use慰ut="this.style.color='#000000';"

>

This?is?a?sample?<B>DIV</B>?element.

</DIV>

<DIV?ID="oDiv2">

This?is?another?sample?<B>DIV</B>?element.

</DIV>

</SPAN>

<INPUT

TYPE="button"

VALUE="Merge?Attributes"

慰nclick="fnMerge()"

>

浠ヤ???瀹瑰??浠ラ????杞?杞斤?杞?杞藉??璇锋敞???ユ????哄?锛?

http://www.cnblogs.com/ttyp/archive/2004/11/15/63900.aspx ?

?

< 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<arguments.length;?i++?)?{

??var?file?=?arguments[i];

??if?(?file.match(//.js$/i))?

???document.write('<script?type=/"text/javascript/ "?src=/"'?+?file?+?'/"></sc'?+?'ript>');

??else

???document.write('<style?type=/"text/css/">@import?/"'?+?file?+?'/"?;</style>');

?}

};

//js??涓?

?

<script?language= "JavaScript">

<!--

//?剧????姣?渚?缂╂??

var?flag=false;

function?DrawImage(ImgD){

?var?image=new?Image();

?var?iwidth?=?80;??//瀹?涔???璁稿?剧??瀹藉害

?var?iheight?=?80;??//瀹?涔???璁稿?剧??楂?搴?

?image.src=ImgD.src;

?if(image.width>0?&&?image.height>0){

?flag=true;

?if(image.width/image.height>=?iwidth/iheight){

??if(image.width>iwidth){??

??ImgD.width=iwidth;

??ImgD.height=(image.height*iwidth)/image.width;

??}else{

??ImgD.width=image.width;??

??ImgD.height=image.height;

??}

??ImgD.alt=image.width+"?"+image.height;

??}

?else{

??if(image.height>iheight){??

??ImgD.height=iheight;

??ImgD.width=(image.width*iheight)/image.height;??

??}else{

??ImgD.width=image.width;??

??ImgD.height=image.height;

??}

??ImgD.alt=image.width+"?"+image.height;

??}

?}

}?

//-->

</script>

<img?src=".."?onload?=?"DrawImage(this)">

?

<IE:clientCaps?ID= "oClientCaps"?style="{behavior:url(#default#clientcaps)}"?/>

<SCRIPT>

var?flash="";

????WMPVersion=?oClientCaps.getComponentVersion("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}","ComponentID");?

????if?(WMPVersion?!=?"")?{

????flash?=?"";

????var?version?=?WMPVersion.split(",");

????var?i;

????for?(i?=?0;?i?<?version.length;?i++)?{

??????if?(i?!=?0)

????flash?+=?".";

??????flash?+=?version[i];

????}

?????document.write("?ㄧ??Windows?Media?Player???????:"+flash+"<p>");

??}

</SCRIPT>

?

<DIV?STYLE= "width:?120px;?height:?50px;?border:?1px?solid?blue;

????????????overflow:?hidden;?text-overflow:ellipsis">

<NOBR>灏辨??姣?濡???涓?琛???瀛?锛?寰??匡?琛ㄦ?煎??涓?琛??剧ず涓?涓?.</NOBR>

</DIV>

?

<html>

<meta?http-equiv= "Content-Type"?content="text/html;?charset=gb2312">

<head>

<script?language="javascript">

var?ie??=navigator.appName=="Microsoft?Internet?Explorer"?true:false;

??

function?keyDown(e)

{

?if(!ie)

?{

??var?nkey=e.which;

??var?iekey='?板?ㄦ??ns娴?瑙???;

??var?realkey=String.fromCharCode(e.which);

?}

?if(ie)

?{

??var?iekey=event.keyCode;

??var?nkey='?板?ㄦ??ie娴?瑙???;

??var?realkey=String.fromCharCode(event.keyCode);

??if(event.keyCode==32){realkey='/'?绌烘??''}

??if(event.keyCode==13){realkey='/'???杞?''}

??if(event.keyCode==27){realkey='/'?Esc/''}

??if(event.keyCode==16){realkey='/'?Shift/''}

??if(event.keyCode==17){realkey='/'?Ctrl/''}

??if(event.keyCode==18){realkey='/'?Alt/''}

?}

?alert('ns娴?瑙??ㄤ腑????'+nkey+'/n'+'ie娴?瑙??ㄤ腑????'+iekey+'/n'+'瀹?????涓?+realkey);

}

document.onkeydown?=?keyDown;

</script>

</head>

<body>

//Javascript?Document.

<hr>

<center>

<h3>璇锋??浠绘??涓?涓???????????</h3>

</center>

</body>

</html>

?

doc?=? new?ActiveXObject("Msxml2.DOMDocument");

doc?=?new?ActiveXObject("Microsoft.XMLDOM")

->>

doc?=?(new?DOMParser()).parseFromString(sXML,'text/xml')

?

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浠f??ORM

?

?

<SCRIPT?language= "VBScript">

Function?URLEncoding(vstrIn)

????strReturn?=?""

????For?i?=?1?To?Len(vstrIn)

????????ThisChr?=?Mid(vStrIn,i,1)

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

????????????strReturn?=?strReturn?&?ThisChr

????????Else

????????????innerCode?=?Asc(ThisChr)

????????????If?innerCode?<?0?Then

????????????????innerCode?=?innerCode?+?&H10000

????????????End?If

????????????Hight8?=?(innerCode??And?&HFF00)/?&HFF

????????????Low8?=?innerCode?And?&HFF

????????????strReturn?=?strReturn?&?"%"?&?Hex(Hight8)?&??"%"?&?Hex(Low8)

????????End?If

????Next

????URLEncoding?=?strReturn

End?Function

Function?bytes2BSTR(vIn)

????strReturn?=?""

????For?i?=?1?To?LenB(vIn)

????????ThisCharCode?=?AscB(MidB(vIn,i,1))

????????If?ThisCharCode?<?&H80?Then

????????????strReturn?=?strReturn?&?Chr(ThisCharCode)

????????Else

????????????NextCharCode?=?AscB(MidB(vIn,i+1,1))

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

????????????i?=?i?+?1

????????End?If

????Next

????bytes2BSTR?=?strReturn

End?Function

dim?strA,oReq

strA?=?URLEncoding("submit1=Submit&text1=涓???")

set?oReq?=?CreateObject("MSXML2.XMLHTTP")

oReq.open?"POST","http://ServerName/VDir/TstResult.asp",false

oReq.setRequestHeader?"Content-Length",Len(strA)

oReq.setRequestHeader?"CONTENT-TYPE","application/x-www-form-urlencoded"

oReq.send?strA

msgbox?bytes2BSTR(oReq.responseBody)

</SCRIPT>

//readyState??xmlhttp杩????版????杩?搴??0=杞藉?ヤ腑,1=????濮???,2=宸茶浇??3=杩?琛?涓?,4=瀹???

?

(1)???借?块??

event.dataTransfer.setData( "URL",?oImage.src);

sImageURL?=?event.dataTransfer.getData("URL")

(2)????璁块??

window.clipboardData.setData("Text",oSource.innerText);

window.clipboardData.getData("Text");

?

<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>

?

<p??style= "page-break-after:always">page1</p>??

<p??style="page-break-after:always">page2</p>??

?

<meta?name= "ROBOTS"?content="灞??у??>

?????朵腑灞??у?兼??浠ヤ?涓?浜?:

????灞??у?间负"all":???浠跺?琚?妫?绱??涓?椤典??炬?ュ??琚??ヨ???

????灞??у?间负"none":???浠朵?琚?妫?绱????涓?涓??ヨ?㈤〉涓????炬?ワ?

????灞??у?间负"index":???浠跺?琚?妫?绱??

????灞??у?间负"follow":??ヨ?㈤〉涓????炬?ワ?

????灞??у?间负"noindex":???浠朵?妫?绱??浣???琚??ヨ?㈤?炬?ワ?

????灞??у?间负"nofollow":?

?

<object?id=min?classid= "clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">?

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

<object?id=max?classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">?

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

<OBJECT?id=close?classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">?

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

<input?type=button?value=??灏????慰nclick=min.Click()>?

<input?type=button?value=??澶у???慰nclick=max.Click()>?

<input?type=button?value=?抽???慰nclick=close.Click()>?

?

<META?HTTP-EQUIV= "pragma"?CONTENT="no-cache">

<META?HTTP-EQUIV="Cache-Control"?CONTENT="no-cache,?must-revalidate">

<META?HTTP-EQUIV="expires"?CONTENT="0">

?

?

<input?type=button?value=瀵煎?ユ?惰??澶孤?慰nclick= "window.external.ImportExportFavorites(true,'http://localhost');">

<input?type=button?value=瀵煎?烘?惰??澶孤?慰nclick="window.external.ImportExportFavorites(false,'http://localhost');">

<input?type=button?value=?寸???惰??澶孤?慰nclick="window.external.ShowBrowserUI('OrganizeFavorites',?null)">

<input?type=button?value=璇?瑷?璁剧疆???慰nclick="window.external.ShowBrowserUI('LanguageDialog',?null)">

<input?type=button?value=???ユ?惰??澶孤?慰nclick="window.external.AddFavorite('http://www.google.com/',?'google')">

<input?type=button?value=???ュ?伴????慰nclick="window.external.addChannel('http://www.google.com/')">

<input?type=button?value=???ュ?伴????慰nclick="window.external.showBrowserUI('PrivacySettings',null)">

?

<input?type=text?慰nkeypress= "return?event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)"?慰npaste="return?!clipboardData.getData('text').match(//D/)"?慰ndragenter="return?false">

继续阅读