2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

超級(jí)實(shí)用且不花哨的js代碼大全

 jinzq 2007-11-29
  • 事件源對(duì)象
    event.srcElement.tagName
    event.srcElement.type
  • 捕獲釋放
    event.srcElement.setCapture();  
    event.srcElement.releaseCapture();  
  • 事件按鍵
    event.keyCode
    event.shiftKey
    event.altKey
    event.ctrlKey
  • 事件返回值
    event.returnValue
  • 鼠標(biāo)位置
    event.x
    event.y
  • 窗體活動(dòng)元素
    document.activeElement
  • 綁定事件
    document.captureEvents(Event.KEYDOWN);
  • 訪(fǎng)問(wèn)窗體元素
    document.all("txt").focus();
    document.all("txt").select();
  • 窗體命令
    document.execCommand
  • 窗體COOKIE
    document.cookie
  • 菜單事件
    document.oncontextmenu
  • 創(chuàng)建元素
    document.createElement("SPAN");  
  • 根據(jù)鼠標(biāo)獲得元素:
    document.elementFromPoint(event.x,event.y).tagName=="TD
    document.elementFromPoint(event.x,event.y).appendChild(ms)  
  • 窗體圖片
    document.images[索引]
  • 窗體事件綁定
    document.onmousedown=scrollwindow;
  • 元素
    document.窗體.elements[索引]
  • 對(duì)象綁定事件
    document.all.xxx.detachEvent(‘onclick‘,a);
  • 插件數(shù)目
    navigator.plugins
  • 取變量類(lèi)型
    typeof($js_libpath) == "undefined"
  • 下拉框
    下拉框.options[索引]
    下拉框.options.length
  • 查找對(duì)象
    document.getElementsByName("r1");
    document.getElementById(id);
  • 定時(shí)
    timer=setInterval(‘scrollwindow()‘,delay);
    clearInterval(timer);
  • UNCODE編碼
    escape() ,unescape
  • 父對(duì)象
    obj.parentElement(dhtml)
    obj.parentNode(dom)
  • 交換表的行
    TableID.moveRow(2,1)
  • 替換CSS
    document.all.csss.href = "a.css";
  • 并排顯示
    display:inline
  • 隱藏焦點(diǎn)
    hidefocus=true
  • 根據(jù)寬度換行
    style="word-break:break-all"
  • 自動(dòng)刷新
    <meta HTTP-EQUIV="refresh" C>
  • 簡(jiǎn)單郵件
    <a  href="
    [email=aaa@bbb.com?subject=ccc&body=xxxyyy]mailto:aaa@bbb.com?subject=ccc&body=xxxyyy[/email]">  
  • 快速轉(zhuǎn)到位置
    obj.scrollIntoView(true)

  • <a name="first">
    <a href="#first">anchors</a>
  • 網(wǎng)頁(yè)傳遞參數(shù)
    location.search();
  • 可編輯
    obj.contenteditable=true
  • 執(zhí)行菜單命令
    obj.execCommand
  • 雙字節(jié)字符
    /[^\x00-\xff]/
    漢字
    /[\u4e00-\u9fa5]/
  • 讓英文字符串超出表格寬度自動(dòng)換行
    word-wrap: break-word; word-break: break-all;
  • 透明背景
    <IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
  • 獲得style內(nèi)容
    obj.style.cssText
  • HTML標(biāo)簽
    document.documentElement.innerHTML
  • 第一個(gè)style標(biāo)簽
    document.styleSheets[0]
  • style標(biāo)簽里的第一個(gè)樣式
    document.styleSheets[0].rules[0]
  • 防止點(diǎn)擊空鏈接時(shí),頁(yè)面往往重置到頁(yè)首端。
    <a href="javascript:function()">word</a>
  • 上一網(wǎng)頁(yè)源
    asp:
    request.servervariables("HTTP_REFERER")
    javascript:
    document.referrer
  • 釋放內(nèi)存
    CollectGarbage();
  • 禁止右鍵
    document.oncontextmenu = function() { return false;}
  • 禁止保存
    <noscript><iframe src="*.htm"></iframe></noscript>
  • 禁止選取<body      Shortcut Icon" href="favicon.ico">
    favicon.ico 名字最好不變16*16的16色,放虛擬目錄根目錄下
  • 收藏欄圖標(biāo)
    <link rel="Bookmark" href="favicon.ico">
  • 查看源碼
    <input type=button value=查看網(wǎng)頁(yè)源代碼 >
  • 關(guān)閉輸入法
    <input style="ime-mode:disabled">
  • 自動(dòng)全選
    <input type=text name=text1 value="123" >
  • ENTER鍵可以讓光標(biāo)移到下一個(gè)輸入框
    <input >
  • 文本框的默認(rèn)值
    <input type=text value="123" >
  • title換行
    obj.title = "123 sdfs "
  • 獲得時(shí)間所代表的微秒
    var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
  • 窗口是否關(guān)閉
    win.closed

  • checkbox扁平
    <input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
  • 獲取選中內(nèi)容
    document.selection.createRange().duplicate().text
  • 自動(dòng)完成功能
    <input  type=text  autocomplete=on>打開(kāi)該功能  
    <input  type=text  autocomplete=off>關(guān)閉該功能
  • 窗口最大化
    <body >
  • 無(wú)關(guān)閉按鈕IE window.open("aa.htm", "meizz", "fullscreen=7");
  • 統(tǒng)一編碼/解碼 alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
    encodeURIComponent對(duì)":"、"/"、";" 和 "?"也編碼

高級(jí)應(yīng)用(一) ~~~~~~~~~~~~~~


//各種尺寸

s  +=  "\r\n網(wǎng)頁(yè)可見(jiàn)區(qū)域?qū)挘?+  document.body.clientWidth;   
s  +=  "\r\n網(wǎng)頁(yè)可見(jiàn)區(qū)域高:"+  document.body.clientHeight;   
s  +=  "\r\n網(wǎng)頁(yè)可見(jiàn)區(qū)域高:"+  document.body.offsetWeight  +"  (包括邊線(xiàn)的寬)";   
s  +=  "\r\n網(wǎng)頁(yè)可見(jiàn)區(qū)域高:"+  document.body.offsetHeight  +"  (包括邊線(xiàn)的寬)";   
s  +=  "\r\n網(wǎng)頁(yè)正文全文寬:"+  document.body.scrollWidth;   
s  +=  "\r\n網(wǎng)頁(yè)正文全文高:"+  document.body.scrollHeight;   
s  +=  "\r\n網(wǎng)頁(yè)被卷去的高:"+  document.body.scrollTop;   
s  +=  "\r\n網(wǎng)頁(yè)被卷去的左:"+  document.body.scrollLeft;   
s  +=  "\r\n網(wǎng)頁(yè)正文部分上:"+  window.screenTop;   
s  +=  "\r\n網(wǎng)頁(yè)正文部分左:"+  window.screenLeft;   
s  +=  "\r\n屏幕分辨率的高:"+  window.screen.height;   
s  +=  "\r\n屏幕分辨率的寬:"+  window.screen.width;   
s  +=  "\r\n屏幕可用工作區(qū)高度:"+  window.screen.availHeight;   
s  +=  "\r\n屏幕可用工作區(qū)寬度:"+  window.screen.availWidth;   




//過(guò)濾數(shù)字

<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf(‘.‘)<0?event.keyCode==46:false)" onpaste="return !clipboardData.getData(‘text‘).match(/\D/)" ondragenter="return false">


//特殊用途

<input type=button value=導(dǎo)入收藏夾 onclick="window.external.ImportExportFavorites(true,‘http://localhost‘);">
<input type=button value=導(dǎo)出收藏夾 onclick="window.external.ImportExportFavorites(false,‘http://localhost‘);">
<input type=button value=整理收藏夾 onclick="window.external.ShowBrowserUI(‘OrganizeFavorites‘, null)">
<input type=button value=語(yǔ)言設(shè)置   onclick="window.external.ShowBrowserUI(‘LanguageDialog‘, null)">
<input type=button value=加入收藏夾 onclick="window.external.AddFavorite(‘http://www.google.com/‘, ‘google‘)">
<input type=button value=加入到頻道 onclick="window.external.addChannel(‘http://www.google.com/‘)">
<input type=button value=加入到頻道 onclick="window.external.showBrowserUI(‘PrivacySettings‘,null)">



//不緩存

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



//正則匹配

匹配中文字符的正則表達(dá)式: [\u4e00-\u9fa5]
匹配雙字節(jié)字符(包括漢字在內(nèi)):[^\x00-\xff]
匹配空行的正則表達(dá)式:\n[\s| ]*\r
匹配HTML標(biāo)記的正則表達(dá)式:/<(.*)>.*<\/\1>|<(.*) \/>/  
匹配首尾空格的正則表達(dá)式:(^\s*)|(\s*$)(像vbscript那樣的trim函數(shù))
匹配Email地址的正則表達(dá)式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配網(wǎng)址URL的正則表達(dá)式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
以下是例子:
利用正則表達(dá)式限制網(wǎng)頁(yè)表單里的文本框輸入內(nèi)容:
用正則表達(dá)式限制只能輸入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,‘‘)" onbeforepaste="clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[^\u4E00-\u9FA5]/g,‘‘))"
1.用正則表達(dá)式限制只能輸入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,‘‘)" onbeforepaste="clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[^\uFF00-\uFFFF]/g,‘‘))"
2.用正則表達(dá)式限制只能輸入數(shù)字:onkeyup="value=value.replace(/[^\d]/g,‘‘) "onbeforepaste="clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[^\d]/g,‘‘))"
3.用正則表達(dá)式限制只能輸入數(shù)字和英文:onkeyup="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>



//無(wú)提示關(guān)閉

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()
   }
}




//取得控件得絕對(duì)位置(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>




//獲得控件的絕對(duì)位置(2)

oRect = obj.getBoundingClientRect();
oRect.left
oRect.



//最小化,最大化,關(guān)閉

<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=最小化 onclick=min.Click()>  
<input type=button value=最大化 onclick=max.Click()>  
<input type=button value=關(guān)閉 onclick=close.Click()>  



//光標(biāo)停在文字最后


<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" onfocus="cc()">


//頁(yè)面進(jìn)入和退出的特效

進(jìn)入頁(yè)面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
推出頁(yè)面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">  
這個(gè)是頁(yè)面被載入和調(diào)出時(shí)的一些特效。duration表示特效的持續(xù)時(shí)間,以秒為單位。transition表示使
用哪種特效,取值為1-23:
  0 矩形縮小  
  1 矩形擴(kuò)大  
  2 圓形縮小
  3 圓形擴(kuò)大  
  4 下到上刷新  
  5 上到下刷新
  6 左到右刷新  
  7 右到左刷新  
  8 豎百葉窗
  9 橫百葉窗  
  10 錯(cuò)位橫百葉窗  
  11 錯(cuò)位豎百葉窗
  12 點(diǎn)擴(kuò)散  
  13 左右到中間刷新  
  14 中間到左右刷新
  15 中間到上下
  16 上下到中間  
  17 右下到左上
  18 右上到左下  
  19 左上到右下  
  20 左下到右上
  21 橫條  
  22 豎條  
  23  



//網(wǎng)頁(yè)是否被檢索 <meta name="ROBOTS" content="屬性值">
  其中屬性值有以下一些:
  屬性值為"all": 文件將被檢索,且頁(yè)上鏈接可被查詢(xún);
  屬性值為"none": 文件不被檢索,而且不查詢(xún)頁(yè)上的鏈接;
  屬性值為"index": 文件將被檢索;
  屬性值為"follow": 查詢(xún)頁(yè)上的鏈接;
  屬性值為"noindex": 文件不檢索,但可被查詢(xún)鏈接;
  屬性值為"nofollow":  



//打印分頁(yè) <p  style="page-break-after:always">page1</p>   
<p  style="page-break-after:always">page2</p>   




//設(shè)置打印

<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=頁(yè)面設(shè)置 onclick="factory.printing.PageSetup()">
<input type=button value=打印預(yù)覽 onclick="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居右顯示頁(yè)碼,第&p頁(yè)/共&P頁(yè)"
   factory.printing.footer = "(自定義頁(yè)腳)"
   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="打印本頁(yè)" onclick="factory.printing.Print(false)">
<input type=button value="頁(yè)面設(shè)置" onclick="factory.printing.PageSetup()">
<input type=button value="打印預(yù)覽" onclick="factory.printing.Preview()"><br>
<a href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static"  target=_blank>具體使用手冊(cè),更多信息,點(diǎn)這里</a>



//自帶的打印預(yù)覽
WebBrowser.ExecWB(1,1) 打開(kāi)  
Web.ExecWB(2,1) 關(guān)閉現(xiàn)在所有的IE窗口,并打開(kāi)一個(gè)新窗口  
Web.ExecWB(4,1) 保存網(wǎng)頁(yè)  
Web.ExecWB(6,1) 打印  
Web.ExecWB(7,1) 打印預(yù)覽  
Web.ExecWB(8,1) 打印頁(yè)面設(shè)置  
Web.ExecWB(10,1) 查看頁(yè)面屬性  
Web.ExecWB(15,1) 好像是撤銷(xiāo),有待確認(rèn)  
Web.ExecWB(17,1) 全選  
Web.ExecWB(22,1) 刷新  
Web.ExecWB(45,1) 關(guān)閉窗體無(wú)提示  
<style media=print>  
.Noprint{display:none;}<!--用本樣式在打印時(shí)隱藏非打印項(xiàng)目-->  
.PageNext{page-break-after: always;}<!--控制分頁(yè)-->  
</style>  
<object  id="WebBrowser"  width=0  height=0  classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">     
</object>     
  
<center class="Noprint" >
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>  
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>  
<input type=button value=頁(yè)面設(shè)置 onclick=document.all.WebBrowser.ExecWB(8,1)>  
</p>  
<p> <input type=button value=打印預(yù)覽 onclick=document.all.WebBrowser.ExecWB(7,1)>  
</center>




//去掉打印時(shí)的頁(yè)眉頁(yè)腳

<script  language="JavaScript">   
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//設(shè)置網(wǎng)頁(yè)打印的頁(yè)眉頁(yè)腳為空
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){}
}
//設(shè)置網(wǎng)頁(yè)打印的頁(yè)眉頁(yè)腳為默認(rèn)值
function  PageSetup_Default()
{   
try
{
  var Wsh=new ActiveXObject("WScript.Shell");
  HKEY_Key="header";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b頁(yè)碼,&p/&P");
  HKEY_Key="footer";
  Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}
catch(e){}
}
</script>
<input type="button" value="清空頁(yè)碼" onclick=PageSetup_Null()>
<input type="button" value="恢復(fù)頁(yè)碼" onclick=PageSetup_Default()>



//瀏覽器驗(yàn)證

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



//計(jì)算內(nèi)容寬和高

<SCRIPT  language="javascript">   
function  test(obj)   
{   
       var  range  =  obj.createTextRange();   
       alert("內(nèi)容區(qū)寬度:  "  +  range.boundingWidth     
                                                 +  "px\r\n內(nèi)容區(qū)高度:  "  +  range.boundingHeight  +  "px");   
              
}   
</SCRIPT>   
<BODY>   
<Textarea id="txt" height="150">sdf</textarea><INPUT  type="button"  value="計(jì)算內(nèi)容寬度"  onClick="test(txt)">   
</BODY>




//無(wú)模式的提示框 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>屏蔽鼠標(biāo)右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格鍵</title>
</head>
<body>
<script language="Javascript"><!--
  //屏蔽鼠標(biāo)右鍵、Ctrl+N、Shift+F10、F11、F5刷新、退格鍵
  //Author: meizz(梅花雨) 2002-6-18
function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠標(biāo)右鍵
function window.onhelp(){return false} //屏蔽F1幫助
function document.onkeydown()
{
  if ((window.event.altKey)&&
      ((window.event.keyCode==37)||   //屏蔽 Alt+ 方向鍵 ←
       (window.event.keyCode==39)))   //屏蔽 Alt+ 方向鍵 →
  {
     alert("不準(zhǔn)你使用ALT+方向鍵前進(jìn)或后退網(wǎng)頁(yè)!");
     event.returnValue=false;
  }
     /* 注:這還不是真正地屏蔽 Alt+ 方向鍵,
     因?yàn)?Alt+ 方向鍵彈出警告框時(shí),按住 Alt 鍵不放,
     用鼠標(biāo)點(diǎn)掉警告框,這種屏蔽方法就失效了。以后若
     有哪位高手有真正屏蔽 Alt 鍵的方法,請(qǐng)告知。*/

  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;}  //屏蔽F11
  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 加鼠標(biāo)左鍵新開(kāi)一網(wǎng)頁(yè)
  if ((window.event.altKey)&&(window.event.keyCode==115))             //屏蔽Alt+F4
  {
      window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
      return false;
  }
}
</script>
屏蔽鼠標(biāo)右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格鍵
</body>
</html>



//屏蔽打印
<style>
@media print{
* {display:none}
}
</style>


//移動(dòng)的圖層,拖動(dòng)

1.<span style=‘position:absolute;width:200;height:200;background:red‘ onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=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" ondrag="doDrag();" onmouseover="this.style.cursor=‘hand‘" style="position:absolute;left=100;top=100;" onmousedown="doMouseDown();">
<a href="#" onclick="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>
  

//文檔狀態(tài)改變

<iframe src="a.html" id="f" name="f" scrolling="no" frameborder=0 marginwidth=0 marginheight=0></iframe>
<script>
var doc=window.frames["f"].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>


//刷新后不變的文本框 <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>


//訪(fǎng)問(wèn)剪貼板

event.dataTransfer.setData("URL", oImage.src);
sImageURL = event.dataTransfer.getData("URL")
(2)普通訪(fǎng)問(wèn)
window.clipboardData.setData("Text",oSource.innerText);
window.clipboardData.getData("Text");



//操作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.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增加參數(shù)

<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 = "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;
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出錯(cuò)!");
}
//window.confirm("下載完成.");
}


//檢驗(yàn)連接是否有效

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

<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返回?cái)?shù)據(jù)的進(jìn)度,0=載入中,1=未初始化,2=已載入,3=運(yùn)行中,4=完成

高級(jí)應(yīng)用(二)~~~~~~~~~~~~~~~~


//組件是否安裝

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




//檢查網(wǎng)頁(yè)是否存在

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



//連接數(shù)據(jù)庫(kù)

<script language="javascript">
  //用 JavaScript 寫(xiě)服務(wù)器端連接數(shù)據(jù)庫(kù)的代碼示例
  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%‘ border=1>";
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>



//使用數(shù)據(jù)島

<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="<< 第一條記錄" onclick="xmldate.recordset.moveFirst()">
<input id="prev" TYPE=button value="<上一條記錄" onclick="xmldate.recordset.movePrevious()">   
<input id="next" TYPE=button value="下一條記錄>" onclick="xmldate.recordset.moveNext()">   
<input id="last" TYPE=button value="最后一條記錄>>" onclick="xmldate.recordset.moveLast()">   
<input id="Add" TYPE=button value="添加新記錄" onclick="xmldate.recordset.addNew()">   

<XML ID="xmldate">
<infolist>
<info ><srno>20041025-01</srno><times>null</times></info>
<info ><srno>20041101-09</srno><times>2004年10月1日2點(diǎn)22分0秒</times></info>
</infolist>
</XML>
</body>
</html>



//獲得參數(shù)

<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);
  alert(s.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>




//設(shè)置光標(biāo)位置

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


//頁(yè)內(nèi)查找

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請(qǐng)?jiān)囍斎腠?yè)面中的關(guān)鍵字再次查找!");
  }
}
return false;
}





//操作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">
//***********默認(rèn)設(shè)置定義.*********************
tPopWait=50;//停留tWait豪秒后顯示提示。
tPopShow=5000;//顯示tShow豪秒后關(guān)閉提示
showPopStep=20;
popOpacity=99;
//***************內(nèi)部變量定義*****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write("<style type=‘text/css‘id=‘defaultPopStyle‘>");
document.write(".cPopText {  background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id=‘dypopLayer‘ style=‘position:absolute;z-index:1000;‘ class=‘cPopText‘></div>");

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<popOpacity) {
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;
</script>



//插入文字

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("<font color=red>插入文字</font>");  
}  
}  




//netscapte下操作xml

doc = new ActiveXObject("Msxml2.DOMDocument");
doc = new ActiveXObject("Microsoft.XMLDOM")
->>
doc = (new DOMParser()).parseFromString(sXML,‘text/xml‘)



//禁止FSO

1.注銷(xiāo)組件
regsvr32 /u scrrun.dll
2.修改PROGID  
HKEY_CLASSES_ROOT\Scripting.FileSystemObject
Scripting.FileSystemObject
3.對(duì)于使用object的用戶(hù),修改HKEY_CLASSES_ROOT\Scripting.



//省略號(hào)

<DIV STYLE="width: 120px; height: 50px; border: 1px solid blue;
            overflow: hidden; text-overflow:ellipsis"
>
<NOBR>就是比如有一行文字,很長(zhǎng),表格內(nèi)一行顯示不下.</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=‘現(xiàn)在是ns瀏覽器‘;
  var realkey=String.fromCharCode(e.which);
}
if(ie)
{
  var iekey=event.keyCode;
  var nkey=‘現(xiàn)在是ie瀏覽器‘;
  var realkey=String.fromCharCode(event.keyCode);
  if(event.keyCode==32){realkey=‘\‘ 空格\‘‘}
  if(event.keyCode==13){realkey=‘\‘ 回車(chē)\‘‘}
  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‘+‘實(shí)際鍵為‘+realkey);
}
document.onkeydown = keyDown;
</script>
</head>
<body>
//Javascript Document.
<hr>
<center>
<h3>請(qǐng)按任意一個(gè)鍵。。。。</h3>
</center>
</body>
</html>




//檢測(cè)media play版本

<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;
    }
     document.write("您的Windows Media Player 版本是:"+flash+"<p>");
  }
</SCRIPT>




//圖象按比例

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




//細(xì)線(xiàn)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<arguments.length; i++ ) {
  var file = arguments;
  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枚舉

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 language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>5)
function window.confirm(str)
{
    execScript("n = msgbox(‘"+ str +"‘, 257)", "vbscript");
    return(n == 1);
}
@end @*/

</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 復(fù)制所有讀/寫(xiě)標(biāo)簽屬性到指定元素。

<SCRIPT>
function fnMerge(){
oSource.children[1].mergeAttributes(oSource.children[0]);
}
</SCRIPT>
<SPAN ID=oSource>
<DIV
ID="oDiv"
ATTRIBUTE1="true"
ATTRIBUTE2="true"
onclick="alert(‘click‘);"
onmouseover="this.style.color=‘#0000FF‘;"
onmouseout="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"
onclick="fnMerge()"
>

JavaScript[對(duì)象.屬性]集錦
SCRIPT 標(biāo)記  

用于包含javascript代碼.  

語(yǔ)法  

屬性  

LANGUAGE 定義腳本語(yǔ)言  

SRC 定義一個(gè)URL用以指定以.JS結(jié)尾的文件


windows對(duì)象  

每個(gè)HTML文檔的頂層對(duì)象.  

屬性  

frames[] 子楨數(shù)組.每個(gè)子楨數(shù)組按源文檔中定義的順序存放.  

feames.length 子楨個(gè)數(shù).  

self 當(dāng)前窗口.  

parent 父窗口(當(dāng)前窗口是中一個(gè)子窗口).  

top 頂層窗口(是所有可見(jiàn)窗口的父窗口).  

status 瀏覽器狀態(tài)窗口上的消息.  

defaultStatus 當(dāng)status無(wú)效時(shí),出現(xiàn)在瀏覽器狀態(tài)窗口上的缺省消息.  

name 內(nèi)部名,為由window.open()方法打開(kāi)的窗口定義的名字.  

方法  

alert("message") 顯示含有給定消息的"javascript Alert"對(duì)話(huà)框.  

confirm("message") 顯示含有給定消息的"Confirm"對(duì)話(huà)框(有一個(gè)OK按鈕和一個(gè)Cancel按鈕).如果用戶(hù)單擊OK返回true,否則返回false.  

prompt("message") 顯示一個(gè)"prompt"對(duì)話(huà)框,要求用戶(hù)根據(jù)顯示消息給予相應(yīng)輸入.  

open("URL","name") 打開(kāi)一個(gè)新窗口,給予一個(gè)指定的名字.  

close() 關(guān)閉當(dāng)前窗口.


frame對(duì)象  

它是整個(gè)瀏覽器窗口的子窗口,除了status,defaultStatus,name屬性外,它擁有window對(duì)象的全部屬性.  

location對(duì)象  

含有當(dāng)前URL的信息.  

屬性  

href 整個(gè)URL字符串.  

protocol 含有URL第一部分的字符串,如http:  

host 包含有URL中主機(jī)名:端口號(hào)部分的字符串.如//www./server/  

hostname 包含URL中主機(jī)名的字符串.如http://www.  

port 包含URL中可能存在的端口號(hào)字符串.  

pathname URL中"/"以后的部分.如~list/index.htm  

hash "#"號(hào)(CGI參數(shù))之后的字符串.  

search "?"號(hào)(CGI參數(shù))之后的字符串.  


document對(duì)象

含有當(dāng)前文檔信息的對(duì)象.

屬性

title 當(dāng)前文檔標(biāo)題,如果未定義,則包含"Untitled".

location 文檔的全URL.

lastModified 含有文檔最后修改日期.

referrer 調(diào)用者URL,即用戶(hù)是從哪個(gè)URL鏈接到當(dāng)前頁(yè)面的.

bgColor 背景色(#xxxxxx)

fgColor 前景文本顏色.

linkColor 超鏈接顏色.

vlinkColor 訪(fǎng)問(wèn)過(guò)的超鏈顏色.

alinkColor 激活鏈顏色(鼠標(biāo)按住未放時(shí)).

forms[] 文檔中form對(duì)象的數(shù)組,按定義次序存儲(chǔ).

forms.length 文檔中的form對(duì)象數(shù)目.

links[] 與文檔中所有HREF鏈對(duì)應(yīng)的數(shù)組對(duì)象,按次序定義存儲(chǔ).

links.length 文檔中HREF鏈的數(shù)目.

anchors[] 錨(...)數(shù)組,按次序定義存儲(chǔ).

anchors.length 文檔中錨的數(shù)目.

方法

write("string") 將字符串突出給當(dāng)前窗口.(字符串可以含有HTML標(biāo)記)

writeln("string") 與write()類(lèi)似,在結(jié)尾追加回車(chē)符,只在預(yù)定格式文本中(...或...)生效.

clear() 清當(dāng)前窗口.

close() 關(guān)閉當(dāng)前窗口.


form對(duì)象

屬性

name

中的NAME屬性的字符串值.

method 中METHOD屬性的類(lèi)值,"0"="GET" ,"1"="POST" .

action 中ACTION屬性的字符串值.

target 表格數(shù)據(jù)提交的目標(biāo),與標(biāo)記中相應(yīng)屬性一致.

elements[index] elements屬性包含form中的各個(gè)元素.

length 表格中的元素個(gè)數(shù).

方法

submit() 提交表格.

事件處理器onSubmit() 用戶(hù)單擊一個(gè)定義好的按鈕提交form時(shí)運(yùn)行的代碼.

text和textarea對(duì)象

屬性

name NAME屬性的字符串值.

value 域內(nèi)容的字符串值.

defaultValue 域內(nèi)容的初始字符串值.

方法

focus() 設(shè)置對(duì)象輸入焦點(diǎn).

blur() 從對(duì)象上移走輸入焦點(diǎn).

select() 選定對(duì)象的輸入?yún)^(qū)域.

事件處理器

onFocus 當(dāng)輸入焦點(diǎn)進(jìn)入時(shí)執(zhí)行.

onBlur 當(dāng)域失去焦點(diǎn)時(shí)執(zhí)行.

onSelect 當(dāng)域中有部分文本被選定時(shí)執(zhí)行.

onChange 當(dāng)域失去焦點(diǎn)且域值相對(duì)于onFocus執(zhí)行有所改變時(shí)執(zhí)行.

復(fù)選框(checkbox)對(duì)象

屬性
name NAME屬性的字符串值.

value 復(fù)選框內(nèi)容的字符串值.如果設(shè)置了,則為"on",否則為"off".

checked 復(fù)選框內(nèi)容的布爾值.如果設(shè)置了,則為true,否則為false .

defaultChecked 反映(CHECKED)屬性的布爾值(缺省狀態(tài)).

方法

click() 選定復(fù)選框,并使之狀態(tài)為"on".

事件處理器

onClick 當(dāng)用戶(hù)單擊Checkbox時(shí)執(zhí)行.


單選按鈕(radio)對(duì)象

屬性

name NAME屬性的字符串值.

length radio對(duì)象中單選按鈕的個(gè)數(shù).

value VALUE屬性的字符串值.

checked 布爾值,按下為true,否則為false .

defaultChecked 反映CHECKED屬性值的布爾值.

方法

click() 選定單選按鈕.

事件處理器

onClick 當(dāng)單選按鈕被選定時(shí)執(zhí)行.


select對(duì)象

屬性

length select對(duì)象中對(duì)象的個(gè)數(shù).

name 由NAME=屬性定義的select對(duì)象的內(nèi)部名.

selectedIndex select對(duì)象中當(dāng)前被選option的下標(biāo).

options 該屬性對(duì)應(yīng)于在HTML中定義select對(duì)象時(shí)標(biāo)記中的內(nèi)容,它有如下屬性:

text 標(biāo)記后的文本串.

value VALUE屬性的值,當(dāng)Submit按鈕被按下時(shí),該值被提交.

defaultSelected 反映標(biāo)記的SELECTED屬性的布爾值.

selected 反映option的當(dāng)前選擇狀態(tài)的布爾值.

事件處理器

onFocus 當(dāng)輸入焦點(diǎn)進(jìn)入域時(shí)執(zhí)行.

onBlur 當(dāng)域失去輸入焦點(diǎn)時(shí)執(zhí)行.

onChange 當(dāng)域失去焦點(diǎn)且如果域的值相對(duì)于onFocus執(zhí)行時(shí)有所改變,則執(zhí)行onChange.


Button對(duì)象

表格中有三種類(lèi)型按鈕,由標(biāo)記中的TYPE屬性定義:

.submit (type="SUBMIT")
.reset (type="RESET")
.custom (type="BUTTON")

所有按鈕對(duì)象都有如下成分:
屬性

value VALUE屬性的字符串值.

name NAME屬性的字符串值.
方法

click() 選定按鈕

事件處理器

onClick 當(dāng)按鈕被單擊時(shí)執(zhí)行.


submit和reset對(duì)象

屬性

value VALUE=屬性的內(nèi)容.

name NAME=屬性的內(nèi)容.

方法

click() 選定按鈕

事件處理器

onClick 當(dāng)按鈕被單擊時(shí)執(zhí)行.


password對(duì)象

屬性

defaultValue VALUE=屬性的內(nèi)容.

name NAME=屬性的內(nèi)容.

value 目前輸入password域的數(shù)據(jù).

方法

focus() 將焦點(diǎn)帶入password域.

blur 將焦點(diǎn)從password域移出.

select() 選定password域中的當(dāng)前數(shù)據(jù),以備修改.


navigator對(duì)象
該對(duì)象用于確定用戶(hù)訪(fǎng)問(wèn)時(shí)使用的Navigator版本.

屬性

appCodeName 相對(duì)于用戶(hù)瀏覽器的"codename"

appName 相對(duì)于用戶(hù)瀏覽器的實(shí)際名字.

appVersion 相對(duì)于用戶(hù)瀏覽器的版本號(hào).

userAgent 該屬性反映用戶(hù)瀏覽器的全部信息.


string對(duì)象

string對(duì)象為操作字符串的內(nèi)容提供了很多方法.

屬性

length 字符串的長(zhǎng)度,即字符串中字符的個(gè)數(shù).

方法

big(),blink(),bold(),fixed(),italics(),small(),sub(),strike(),sup(),fontColor(color),fontSize(size)

以上方法為字符串增加相應(yīng)的HTML標(biāo)記.

charAt(index) 返回字符串中index處的字符.

indexOf(searchValue,[fromIndex]) 該方法在字符串中尋找第一次出現(xiàn)的searchValue.如果給定了fromIndex,則從 字符串內(nèi)該位置開(kāi)始搜索,當(dāng)searchValue找到后,返回該串第一個(gè)字符的位置.

lastIndexOf(searchValue,[fromIndex]) 從字符串的尾部向前搜索searchValue,并報(bào)告找到的第一個(gè)實(shí)例.

substring(indexA,indexB) 獲取自indexA到indexB的子串.

toLowerCase(),toUpperCase() 將字符串中所有字符全部轉(zhuǎn)換成大寫(xiě),小寫(xiě).


Date對(duì)象

要使用Date對(duì)象,必須先生成一個(gè)Date實(shí)例:

變量名=new Date();

方法
getDay(),getDate(),getHours(),getMinutes(),getMonth(),getSeconds(),getTime(),
getTimeZoneOffset(),getYear()

還有setDay... ...

toGMTString() 用GMT格式返回當(dāng)前時(shí)間. (Sun,12 Feb 1999 14:19:22 GMT)

toLocaleString 用locale格式返回當(dāng)前時(shí)間. (03/11/99 14:19:22)

parse(date) 將普通date字符串轉(zhuǎn)換成豪秒形式,從而給setTime()做參數(shù).


Math對(duì)象

屬性

LN10 (10的自然對(duì)數(shù))

PI (3.1415926...)

SQRT1_2 (1/2的平方根)

方法

abs(x) 返回x的絕對(duì)值
acos(x) 返回x的arc cosine值
asin(x) 返回x的arc sin值
atan(x) 返回x的arc tangent值
ceil(x) 返回大于等于x的最小整數(shù)
cos(x) 返回x的cosine值
exp(x) 返回e的x次方
floor(x) 返回小于等于x的最大整數(shù)
log(x) 返回x的
max(x,y) 返回x,y中的大值
min(x,y) 返回x,y中的小值
pow(x,y) 返回x的y次方
round(x) 舍入到最近整數(shù),(小于或等于0.5小數(shù)舍去)
sin(x) 返回x的sin值
sqrt(x) 返回x的平方根
tan(x) 返回x的tangent值

彈窗代碼匯總
【0、超完美彈窗代碼
功能:5小時(shí)彈一次+背后彈出+自動(dòng)適應(yīng)不同分辯率+準(zhǔn)全屏顯示

代碼:
<script>
function openwin(){
window.open(http://www.,"pop1","width="+(window.screen.width-15)+",height="+(window.screen.height-170)+",left=0,top=0,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes")
setTimeout("focus();",5);
}
function get_cookie(Name) {
var search = Name + "="
var return&#118alue = "";
if (documents&#46cookie.length > 0) {
offset = documents&#46cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents&#46cookie.indexOf(";", offset);
if (end == -1)
end = documents&#46cookie.length;
return&#118alue=unescape(documents&#46cookie.substring(offset, end))
}
}
return return&#118alue;
}
function Set()
{
  var Then = new Date()    
  Then.setTime(Then.getTime() + 5*60*60*1000 )
  documents&#46cookie = "popped1=yes;expires="+ Then.toGMTString()
}

function loadpopup(){
if (get_cookie(‘popped1‘)==‘‘)
{
openwin()
Set()
}
}
setTimeout("loadpopup()",5);

</script>


【1、最基本的彈出窗口代碼】

其實(shí)代碼非常簡(jiǎn)單:

<script language="&#106avascript">
<!--
window.open (‘page.html‘)
-->
</script>
因 為著是一段&#106avascripts代碼,所以它們應(yīng)該放在<script language="&#106avascript">標(biāo)簽和</script>之間。<!-- 和 -->是對(duì)一些版本低的瀏覽器起作用,在這些老瀏覽器中不會(huì)將標(biāo)簽中的代碼作為文本顯示出來(lái)。要養(yǎng)成這個(gè)好習(xí)慣啊。
window.open (‘page.html‘) 用于控制彈出新的窗口page.html,如果page.html不與主窗口在同一路徑下,前面應(yīng)寫(xiě)明路徑,絕對(duì)路徑(http://)和相對(duì)路徑(../)均可。用單引號(hào)和雙引號(hào)都可以,只是不要混用。
這一段代碼可以加入html的任意位置,<head>和</head>之間可以,<body>間</body>也可以,越前越早執(zhí)行,尤其是頁(yè)面代碼長(zhǎng),又想使頁(yè)面早點(diǎn)彈出就盡量往前放。


【2、經(jīng)過(guò)設(shè)置后的彈出窗口】

下面再說(shuō)一說(shuō)彈出窗口的設(shè)置。只要再往上面的代碼中加一點(diǎn)東西就可以了。
我們來(lái)定制這個(gè)彈出的窗口的外觀,尺寸大小,彈出的位置以適應(yīng)該頁(yè)面的具體情況。
<script language="&#106avascript">
<!--
window.open (‘page.html‘, ‘newwindow‘, ‘height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no‘)
//寫(xiě)成一行
-->
</script>
參數(shù)解釋?zhuān)?
<script language="&#106avascript"> js腳本開(kāi)始;
window.open 彈出新窗口的命令;
‘page.html‘ 彈出窗口的文件名;
‘newwindow‘ 彈出窗口的名字(不是文件名),非必須,可用空‘‘代替;
height=100 窗口高度;
width=400 窗口寬度;
top=0 窗口距離屏幕上方的象素值;
left=0 窗口距離屏幕左側(cè)的象素值;
toolbar=no 是否顯示工具欄,yes為顯示;
menubar,scrollbars 表示菜單欄和滾動(dòng)欄。
resizable=no 是否允許改變窗口大小,yes為允許;
location=no 是否顯示地址欄,yes為允許;
status=no 是否顯示狀態(tài)欄內(nèi)的信息(通常是文件已經(jīng)打開(kāi)),yes為允許;
</script> js腳本結(jié)束


【3、用函數(shù)控制彈出窗口】

下面是一個(gè)完整的代碼。
<html>
<head>
<script language="&#106avascript">
<!--
function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar=
no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
//寫(xiě)成一行
}
//-->
</script>
</head>
<body >
...任意的頁(yè)面內(nèi)容...
</body>
</html>
這里定義了一個(gè)函數(shù)openwin(),函數(shù)內(nèi)容就是打開(kāi)一個(gè)窗口。在調(diào)用它之前沒(méi)有任何用途。
怎么調(diào)用呢?
方法一:<body > 瀏覽器讀頁(yè)面時(shí)彈出窗口;
方法二:<body > 瀏覽器離開(kāi)頁(yè)面時(shí)彈出窗口;
方法三:用一個(gè)連接調(diào)用:
<a href="#" _fcksavedurl=""#"" &#111nclick="openwin()">打開(kāi)一個(gè)窗口</a>
注意:使用的“#”是虛連接。
方法四:用一個(gè)按鈕調(diào)用:
<input type="button" &#111nclick="openwin()" &#118alue="打開(kāi)窗口">


【4、同時(shí)彈出2個(gè)窗口】

對(duì)源代碼稍微改動(dòng)一下:
<script language="&#106avascript">
<!--
function openwin()
{ window.open ("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
//寫(xiě)成一行
window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
//寫(xiě)成一行
}
//-->
</script>
為避免彈出的2個(gè)窗口覆蓋,用top和left控制一下彈出的位置不要相互覆蓋即可。最后用上面說(shuō)過(guò)的四種方法調(diào)用即可。

注意:2個(gè)窗口的name(newwindows和newwindow2)不要相同,或者干脆全部為空。ok?


【5、主窗口打開(kāi)文件1.htm,同時(shí)彈出小窗口page.html】

如下代碼加入主窗口<head>區(qū):
<script language="&#106avascript">
<!--
function openwin()
{window.open("page.html","","width=200,height=200"
}
//-->
</script>
加入<body>區(qū):
<a href="1.htm" &#111nclick="openwin()">open</a>即可。


【6、彈出的窗口之定時(shí)關(guān)閉控制】

下面我們?cè)賹?duì)彈出的窗口進(jìn)行一些控制,效果就更好了。如果我們?cè)賹⒁恍《未a加入彈出的頁(yè)面(注意是加入到page.html的html中,可不是主頁(yè)面中,否則...),讓它10秒后自動(dòng)關(guān)閉是不是更酷了?

首先,將如下代碼加入page.html文件的<head>區(qū):
<script language="&#106avascript">
function closeit()
{settimeout("self.close()",10000) //毫秒}
</script>
然后,再用<body > 這一句話(huà)代替page.html中原有的<body>這一句就可以了。(這一句話(huà)千萬(wàn)不要忘記寫(xiě)??!這一句的作用是調(diào)用關(guān)閉窗口的代碼,10秒鐘后就自行關(guān)閉該窗口。)


【7、在彈出窗口中加上一個(gè)關(guān)閉按鈕】

<form>
<input type=‘button‘ &#118alue=‘關(guān)閉‘ &#111nclick=‘window.close()‘>
</form>

呵呵,現(xiàn)在更加完美了!


【8、內(nèi)包含的彈出窗口-一個(gè)頁(yè)面兩個(gè)窗口】

上面的例子都包含兩個(gè)窗口,一個(gè)是主窗口,另一個(gè)是彈出的小窗口。

通過(guò)下面的例子,你可以在一個(gè)頁(yè)面內(nèi)完成上面的效果。
<html>
<head>
<script language="&#106avascript">
function openwin()
{openwindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no";
//寫(xiě)成一行
openwindow.document.write("<title>例子</title>"
openwindow.document.write("<body bgcolor=#ffffff>"
openwindow.document.write("<h1>hello!</h1>"
openwindow.document.write("new window opened!"
openwindow.document.write("</body>"
openwindow.document.write("</html>"
openwindow.document.close()}
</script>
</head>
<body>
<a href="#" &#111nclick="openwin()">打開(kāi)一個(gè)窗口</a>
<input type="button" &#111nclick="openwin()" &#118alue="打開(kāi)窗口">
</body>
</html>
看看 openwindow.document.write()里面的代碼不就是標(biāo)準(zhǔn)的html嗎?只要按照格式寫(xiě)更多的行即可。千萬(wàn)注意多一個(gè)標(biāo)簽或少一個(gè)標(biāo)簽就會(huì)出現(xiàn)錯(cuò)誤。記得用openwindow.document.close()結(jié)束啊。

【9、終極應(yīng)用--彈出的窗口之cookie控制】

回 想一下,上面的彈出窗口雖然酷,但是有一點(diǎn)小毛病(沉浸在喜悅之中,一定沒(méi)有發(fā)現(xiàn)吧?)比如你將上面的腳本放在一個(gè)需要頻繁經(jīng)過(guò)的頁(yè)面里(例如首頁(yè)),那 么每次刷新這個(gè)頁(yè)面,窗口都會(huì)彈出一次,是不是非常煩人?:-(有解決的辦法嗎?yes! ;-) follow me.

我們使用cookie來(lái)控制一下就可以了。

首先,將如下代碼加入主頁(yè)面html的<head>區(qū):
<script>
function openwin()
{window.open("page.html","","width=200,height=200"}
function get_cookie(name)
{var search = name + "="
var return&#118alue = "";
if (documents&#46cookie.length > 0) {
offset = documents&#46cookie.indexof(search)
if (offset != -1) {
offset += search.length
end = documents&#46cookie.indexof(";", offset);
if (end == -1)
end = documents&#46cookie.length;
return&#118alue=unescape(documents&#46cookie.substring(offset,end))
}
}
return return&#118alue;
}
function loadpopup(){
if (get_cookie(‘popped‘)==‘‘){
openwin()
documents&#46cookie="popped=yes"
}
}
</script>
然后,用<body >(注意不是openwin而是loadpop?。。┨鎿Q主頁(yè)面中原有的<body>這一句即可。你可以試著刷新一下這個(gè)頁(yè)面或重新進(jìn)入該頁(yè)面,窗口再也不會(huì)彈出了。真正的pop-only-once!
強(qiáng)力彈窗代碼:

<Script Language="&#106avascript">
var paypopupURL = "http://";
var usingActiveX = true;
function blockError(){return true;}
window.&#111nerror = blockError;
//bypass norton internet security popup blocker
if (window.SymRealWinOpen){window.open = SymRealWinOpen;}
if (window.NS_ActualOpen) {window.open = NS_ActualOpen;}
if (typeof(usingClick) == ‘undefined‘) {var usingClick = false;}
if (typeof(usingActiveX) == ‘undefined‘) {var usingActiveX = false;}
if (typeof(popwin) == ‘undefined‘) {var popwin = null;}
if (typeof(poped) == ‘undefined‘) {var poped = false;}
if (typeof(paypopupURL) == ‘undefined‘) {var paypopupURL = "http:///";}
var blk = 1;
var setupClickSuccess = false;
var googleInUse = false;
var myurl = location.href+‘/‘;
var MAX_TRIED = 20;
var activeXTried = false;
var tried = 0;
var randkey = ‘0‘; // random key from server
var myWindow;
var popWindow;
var setupActiveXSuccess = 0;
// bypass IE functions
function setupActiveX()

{if (usingActiveX)

{try

{if (setupActiveXSuccess < 5)

{document.write(‘<INPUT STYLE="display:none;" ID="autoHit" TYPE="TEXT" &#111nKEYPRESS="showActiveX()">‘);

popWindow=window.createPopup();

popWindow.document.body.innerHTML=‘<DIV ID="objectRemover"><OBJECT ID="getParentDiv" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="‘+myurl+‘/paypopup.html" TYPE="text/html"></OBJECT></DIV>‘;

document.write(‘<IFRAME NAME="popIframe" STYLE="position:absolute;top:-100px;left:0px;width:1px;height:1px;" SRC="about&#58blank"></IFRAME>‘);

popIframe.document.write(‘<OBJECT ID="getParentFrame" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="‘+myurl+‘/paypopup.html" TYPE="text/html"></OBJECT>‘);

setupActiveXSuccess = 6;}}catch(e){if (setupActiveXSuccess < 5) {setupActiveXSuccess++;setTimeout(‘setupActiveX();‘,500);}else if (setupActiveXSuccess == 5) {activeXTried = true;setupClick();
}
}
}
}
function tryActiveX()
{if (!activeXTried && !poped)

{if (setupActiveXSuccess == 6 && googleInUse && popWindow && popWindow.document.getElementById(‘getParentDiv‘) && popWindow.document.getElementById(‘getParentDiv‘).object && popWindow.document.getElementById(‘getParentDiv‘).object.parentWindow)

{
myWindow=popWindow.document.getElementById(‘getParentDiv‘).object.parentWindow;
}

else if (setupActiveXSuccess == 6 && !googleInUse && popIframe && popIframe.getParentFrame && popIframe.getParentFrame.object && popIframe.getParentFrame.object.parentWindow)

{
myWindow=popIframe.getParentFrame.object.parentWindow;popIframe.location.replace(‘a(chǎn)bout&#58blank‘);
}

else
{
setTimeout(‘tryActiveX()‘,200);tried++;
if (tried >= MAX_TRIED && !activeXTried)
{
activeXTried = true;setupClick();
}
return;
}

openActiveX();
window.windowFired=true;self.focus();
}
}

function openActiveX()
{if (!activeXTried && !poped)
{if (myWindow && window.windowFired)
{
window.windowFired=false;
document.getElementById (‘a(chǎn)utoHit‘).fireEvent("&#111nkeypress",(document.createEventObject(). keyCode=escape(randkey).substring(1)));
}
else
{
setTimeout(‘openActiveX();‘,100);
}
tried++;
if (tried >= MAX_TRIED)
{activeXTried = true;setupClick();
}
}
}
function showActiveX()
{
if (!activeXTried && !poped)
{if (googleInUse)
{window.daChildObject=popWindow.document.getElementById(‘objectRemover‘).children(0);
window.daChildObject=popWindow.document.getElementById(‘objectRemover‘).removeChild(window.daChildObject);
}
newWindow=myWindow.open(paypopupURL,‘a(chǎn)bcdefg‘);
if (newWindow)
{
newWindow.blur();
self.focus();activeXTried = true;poped = true;
}
else
{
if (!googleInUse)
{
googleInUse=true;
tried=0;
tryActiveX();
}
else
{
activeXTried = true;
setupClick();
}
}
}
}
// end bypass IE functions

// normal call functions


function paypopup()
{if (!poped)
{if(!usingClick && !usingActiveX)
{popwin = window.open(paypopupURL,‘a(chǎn)bcdefg‘);
if (popwin)
{poped = true;
}
self.focus();
}
}
if (!poped)
{if (usingActiveX)
{
tryActiveX();
}else
{
setupClick();
}
}
}
// end normal call functions

// &#111nclick call functions

function setupClick()
{if (!poped && !setupClickSuccess)
{
if (window.Event)
document.captureEvents(Event.CLICK);
prePaypop&#111nclick = document.&#111nclick;
document.&#111nclick = gopop;self.focus();
setupClickSuccess=true;
}
}


function gopop()
{if (!poped)
{
popwin = window.open(paypopupURL,‘a(chǎn)bcdefg‘);
if (popwin)
{
poped = true;
}
self.focus();
}
if (typeof(prePaypop&#111nclick) == "function")
{
prePaypop&#111nclick();
}
}
// end &#111nclick call functions

// check version


function detectGoogle()
{if (usingActiveX)
{
try {
document.write(‘<DIV STYLE="display:none;"><OBJECT ID="detectGoogle" CLASSID="clsid:00EF2092-6AC5-47c0-BD25-CF2D5D657FEB" STYLE="display:none;" CODEBASE="view-source:about&#58blank"></OBJECT></DIV>‘);
googleInUse|=(typeof(document.getElementById(‘detectGoogle‘))==‘object‘);
}
catch(e)
{
setTimeout(‘detectGoogle();‘,50);
}
}
}


function version()
{
var os = ‘W0‘;
var bs = ‘I0‘;
var isframe = false;
var browser = window.navigator.userAgent;
if (browser.indexOf(‘Win‘) != -1)
{
os = ‘W1‘;
}
if (browser.indexOf("SV1") != -1)
{
bs = ‘I2‘;
}
else if (browser.indexOf("Opera") != -1)
{
bs = "I0";
}
else if (browser.indexOf("Firefox") != -1)
{
bs = "I0";
}
else if (browser.indexOf("Microsoft") != -1 || browser.indexOf("MSIE") != -1)
{
bs = ‘I1‘;
}
if (top.location != this.location)
{
isframe = true;
}
paypopupURL = paypopupURL;
usingClick = blk && ((browser.indexOf("SV1") != -1) || (browser.indexOf("Opera") != -1) || (browser.indexOf("Firefox") != -1));
usingActiveX = blk && (browser.indexOf("SV1") != -1) && !(browser.indexOf("Opera") != -1) && ((browser.indexOf("Microsoft") != -1) || (browser.indexOf("MSIE") != -1));

detectGoogle();}
version();

// end check version

function loadingPop() {
if(!usingClick && !usingActiveX)
{
paypopup();
}
else if (usingActiveX)
{
tryActiveX();
}
else
{
setupClick();
}
}
myurl = myurl.substring(0, myurl.indexOf(‘/‘,8));
if (myurl == ‘‘)
{
myurl = ‘.‘;
}
setupActiveX();
loadingPop();
self.focus();
</Script>

JS代碼判斷集錦(之一) ~~~~~~~~~~~~~~~~~~


<script language="JavaScript">
function checkid(iden,year,month,day){

if (iden.value.length==15) {


if ((iden.value.lastIndexOf(month.value+day.value))==8) {

return true;
}
return false;
}
if (iden.value.length==18) {


if ((iden.value.indexOf(year.value+month.value+day.value))==6) {

return true;
}
return false;
}

return false;
}


function isCharsInBag (s, bag)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) return false;
}
return true;
}
function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{
var whitespace = " \t\n\r";
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) >= 0)
{
return true;
}
}
return false;
}
function isEmail (s,t)
{
if (isEmpty(s))
{
window.alert("輸入的E-mail地址不能為空,請(qǐng)輸入!");
mobj = eval(t);
mobj.focus();
mobj.select();
return false
}
if (isWhitespace(s))
{
window.alert("輸入的E-mail地址中不能包含空格符,請(qǐng)重新輸入!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
var i = 1;
var len = s.length;

if (len > 50)
{
window.alert("email地址長(zhǎng)度不能超過(guò)50位!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}

pos1 = s.indexOf("@");
pos2 = s.indexOf(".");
pos3 = s.lastIndexOf("@");
pos4 = s.lastIndexOf(".");
if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len))
{
window.alert("請(qǐng)輸入有效的E-mail地址!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
else
{
if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
|| ( pos1 != pos3 )
|| ( pos4 < pos3 ) )
{
window.alert("請(qǐng)輸入有效的E-mail地址!");
mobj = eval(t)
mobj.focus()
mobj.select()
return false;
}
}

if ( !isCharsInBag( s, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@"))
{
window.alert("email地址中只能包含字符ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_@\n" + "請(qǐng)重新輸入" );
mobj = eval(t)
mobj.focus()
return false;
}
return true;
}
function isnumber(str){
var digits="1234567890";
var i=0;
var strlen=str.length;
while((i<strlen)){
var char=str.charAt(i);
if(digits.indexOf(char)==-1)return false;i++;
}
return true;
}
function isnumbercode(str){
var digits="1234567890-/";
var i=0;
var strlen=str.length;
while((i<strlen)){
var char=str.charAt(i);
if(digits.indexOf(char)==-1)return false;i++;
}
return true;
}
</script>

<script language=javascript>
function checkForm(theform){
if (document.frm.companyname.value.length==0){
alert("單位名稱(chēng)不能為空。");
mobj = eval("document.frm.companyname");
mobj.focus()
mobj.select()
return false;
}

if (document.frm.address.value.length==0){
alert("單位地址不能為空");
mobj = eval("document.frm.address");
mobj.focus()
mobj.select()
return false;
}

if (document.frm.invest.value.length==0){
alert("投資額不能為空");
mobj = eval("document.frm.invest");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.codeornumber.value.length==0){
alert("法人代碼證書(shū)號(hào)或營(yíng)業(yè)執(zhí)照編號(hào)不能為空");
mobj = eval("document.frm.codeornumber");
mobj.focus()
mobj.select()
return false;
}

if (document.frm.linkman.value.length==0){
alert("聯(lián)系人不能為空");
mobj = eval("document.frm.linkman");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.linkmanjob.value.length==0){
alert("聯(lián)系人職位不能為空");
mobj = eval("document.frm.linkmanjob");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.phone.value.length==0){
alert("電話(huà)不能為空");
mobj = eval("document.frm.phone");
mobj.focus()
mobj.select()
return false;
}

if (document.frm.email.value==‘‘) {
window.alert ("請(qǐng)輸入您的E-mail地址 !")
mobj = eval("document.frm.email");
mobj.focus()
mobj.select()
return false
}
if ( !isEmail(document.frm.email.value,document.frm.email) )
return false
if (document.frm.introduction.value.length==0){
alert("公司簡(jiǎn)介不能為空");
mobj = eval("document.frm.introduction");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.positionname.value.length==0){
alert("職位名稱(chēng)不能為空");
mobj = eval("document.frm.positionname");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.jobaddress.value.length==0){
alert("工作地點(diǎn)不能為空");
mobj = eval("document.frm.jobaddress");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.jobfunction.value.length==0){
alert("工作職責(zé)不能為空");
mobj = eval("document.frm.jobfunction");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.positionrequre.value.length==0){
alert("職位要求不能為空");
mobj = eval("document.frm.positionrequre");
mobj.focus()
mobj.select()
return false;
}
if (document.frm.salary.value.length==0){
alert("待遇不能為空");
mobj = eval("document.frm.salary");
mobj.focus()
mobj.select()
return false;
}
}
</script>

JS代碼判斷集錦(之二)

<INPUT TYPE="button" value="登錄"  tabindex="4">

<INPUT TYPE="button" value="注冊(cè)"  tabindex="4">

//////////////////////////////////////////////

function trim(inputstr) //去處空格,在獲取客戶(hù)端錄入的表單信息前,
都先trim一下再提交 例如:“form1.org_name.value = trim(form1.org_name.value);”
{
if(!inputstr.length>0) return "";
var starts=0;
var ends=inputstr.length;
while(starts<ends)
{
if(inputstr.substring(starts,starts+1)==" ")
starts++;
else
break;
}
while(starts<ends)
{
if(inputstr.substring(ends-1,ends)==" ")
ends--;
else
break;
}
return inputstr.substring(starts,ends);
}

function isvalidcode(inputs) //校驗(yàn)郵政編碼
{
var i,temp;
var isvalidcode = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=6) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!(temp>="0" && temp<="9"))
{
isvalidcode=false;
break;
}
}
return isvalidcode;
}

function isvalidtel(inputs) //校驗(yàn)電話(huà)號(hào)碼
{
var i,temp;
var isvalidtel = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!(temp>="0" && temp<="9" || temp=="-"))
{
isvalidtel=false;
break;
}
}
return isvalidtel;
}

function isrealnum(inputs) //校驗(yàn)實(shí)數(shù)(含小數(shù)點(diǎn))
{
var i,temp;
var isrealnum = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!(temp>="0" && temp<="9" || temp=="."))
{
isrealnum=false;
break;
}
}
return isrealnum;
}

function isnumeric(inputs) //校驗(yàn)是否整數(shù)
{
var i,temp;
var isnumeric = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0) return false;
//isvalid = true;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!(temp>="0" && temp<="9"))
{
isnumeric=false;
break;
}
}
return isnumeric;
}

function isvalidide(inputs) //校驗(yàn)身份證
{
var i,temp;
var isvalidide = true;
inputstr=trim(inputs);
if(inputstr.length == null || inputstr.length == 0 || (inputstr.length != 15 && inputstr.length != 18)) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!((temp>="0" && temp<="9") || temp == "x" || temp == "X"))
{
isvalidide=false;
break;
}
}
return isvalidide;
}

function isvalidname(inputs) //校驗(yàn)賬號(hào)2~15位(即只能是英文字母和數(shù)字組成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 15 || inputstr.length < 2) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}

function isvalidphoto(inputs) //校驗(yàn)照片擴(kuò)展名
{
var i,temp;
var isvalidphoto = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0) return true; //沒(méi)有相片也允許的
temp=inputstr.substring(inputstr.lastIndexOf(".")+1);

temp = temp.toLowerCase();
if(!(temp == "bmp" || temp == "jpg" || temp == "gif"))
{
isvalidphoto=false;
}
return isvalidphoto;
}

function isvalidzgh(inputs) //校驗(yàn)職工號(hào)8位(即只能是英文字母和數(shù)字組成的串)
{
var i,temp;
var isvalidzgh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 8) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidzgh=false;
break;
}
}
return isvalidzgh;
}

function isvalidxh(inputs) //校驗(yàn)學(xué)號(hào)7位(即只能是英文字母和數(shù)字組成的串)
{
var i,temp;
var isvalidxh = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length != 7) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidxh=false;
break;
}
}
return isvalidxh;
}

function isvalidkcid(inputs) //校驗(yàn)課程編號(hào)5位(即只能是數(shù)字組成的串)
{
var i,temp;
var isvalidkcid = true;
inputstr=trim(inputs);
if(inputstr.length==null||inputstr.length==0||inputstr.length!=5) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!(temp>="0" && temp<="9"))
{
isvalidkcid=false;
break;
}
}
return isvalidkcid;
}

function isvalidnamee(inputs) //校驗(yàn)賬號(hào)4~20位(即只能是英文字母和數(shù)字組成的串)
{
var i,temp;
var isvalidname = true;
inputstr=trim(inputs);
if(inputstr.length==null || inputstr.length==0 || inputstr.length > 20 || inputstr.length < 4) return false;
for(i=0;i<inputstr.length;i++)
{
temp=inputstr.substring(i,i+1);

if(!((temp >= "0" && temp <= "9") || (temp >= "a" && temp <= "z") || (temp >= "A" && temp <= "Z")))
{
isvalidname=false;
break;
}
}
return isvalidname;
}


==========================

<Script language="JavaScript">
function login()
{
form1.UNAME.value = trim(form1.UNAME.value);
form1.PWD.value = trim(form1.PWD.value);
form1.PWD2.value = trim(form1.PWD2.value);
form1.EMAIL.value = trim(form1.EMAIL.value);
form1.NC.value = trim(form1.NC.value);
if(!isvalidname(form1.UNAME.value))
{
alert("請(qǐng)您注意:用戶(hù)名必須為『2~15位英文或數(shù)字』!");
form1.UNAME.focus();
return false;
}
else if(!isvalidname(form1.PWD.value))
{
alert("請(qǐng)您注意:密碼必須為『2~15位英文或數(shù)字』!");
form1.PWD.focus();
return false;
}
else if(!isvalidname(form1.PWD2.value))
{
alert("請(qǐng)您注意:密碼確認(rèn)也必須為『2~15位英文或數(shù)字』!");
form1.PWD2.focus();
return false;
}
else if(form1.PWD.value != form1.PWD2.value)
{
alert("兩次密碼不一致!");
form1.PWD.focus();
return false;
}
else if(form1.EMAIL.value == "" || form1.EMAIL.value.length > 100)
{
alert("請(qǐng)輸入郵件!");
form1.EMAIL.focus();
return false;
}
else if(form1.NC.value == "" || form1.NC.value.length > 15)
{
alert("請(qǐng)輸入昵稱(chēng)!");
form1.NC.focus();
return false;
}
else if(window.confirm("您確信提交!"))
return true;
else
return false;
}

function regedit()
{
var litop = (screen.height - 162)/2;
var lileft = (screen.width - 360)/2;
window.open("/regedit.aspx", "reg", "titlebar=no,fullscreen=no,dependent=yes,height=162,width=360,
top=" + litop + ",left=" + lileft + ",
toolbar=no,menubar=no,scrollbars=no,resizable=no,
channelmode=no,status=no,location=no,directories=no");
}
</Script>

1. 禁止復(fù)制(copy),禁用鼠標(biāo)右鍵!

<SCRIPT>
//加入頁(yè)面保護(hù)
function rf()
{return false; }
document.oncontextmenu = rf
function keydown()
{if(event.ctrlKey ==true || event.keyCode ==93 || event.shiftKey ==true){return false;} }
document.onkeydown =keydown
function drag()
{return false;}
document.ondragstart=drag
function stopmouse(e) {
if (navigator.appName == ‘Netscape‘ && (e.which == 3 || e.which == 2))
return false;
else if
(navigator.appName == ‘Microsoft Internet Explorer‘ && (event.button == 2 || event.button == 3)) {
alert("版權(quán)沒(méi)有,但別復(fù)制 :)");
return false;
}
return true;
}
document.onmousedown=stopmouse;
if (document.layers)
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=stopmouse;

</SCRIPT>
<script language="javascript">
function JM_cc(ob){
var obj=MM_findObj(ob); if (obj) {
obj.select();js=obj.createTextRange();js.execCommand("Copy");}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
</script>

2. JS和HTML互轉(zhuǎn) ~~~~~~~~~  

<body>
<style>
body{font-size:9pt}
textarea {color="#707888";font-family:"verdana"}
.inputs {color="#707888";border:1px solid;background:#f4f4f4}
</style>
在這里輸入你需要轉(zhuǎn)換的格式,可以是JavaScript也可以是DHtml.
<br>
<textarea id="codes" style="width:730;height:300">
</textarea>
<br>
<button  class="inputs">
清除輸出
</button>
<button  class="inputs">
全選代碼
</button>
<button  class="inputs">
拷貝代碼
</button>
<button  class="inputs">
粘貼代碼
</button>
<button  class="inputs">
Js轉(zhuǎn)Html
</button>
<button  class="inputs">
Html轉(zhuǎn)Js
</button>
<button  class="inputs">
點(diǎn)擊顯示源文件
</button>
<button  class="inputs">
預(yù)覽代碼[F12]
</button>
<br>
這個(gè)是輸出格式的窗口:
<br>
<textarea id="outputs" style="width:730;height:300"></textarea>
<br>
一個(gè)不好的消息:這個(gè)Js轉(zhuǎn)Html部分現(xiàn)在只是支持由這個(gè)程序生成的
<br>
作者:FlashSoft2000 QQ:14433548
<input id="hide" style=‘display:none‘>
<script>
//定義title
document.title="多功能網(wǎng)頁(yè)轉(zhuǎn)換"
//顯示網(wǎng)頁(yè)源文件
function writes()
{
outputs.value=document.body.outerHTML;
}
//清除輸出窗口
function clears()
{
outputs.innerHTML=‘‘;
}
//替換特定字符
//n1字符串,n2要替換的字,n3替換的字
function commute(n1,n2,n3)
{
var a1,a2,a3=0,a0=‘‘
a1=n1.length;
a2=n2.length;
for(x=0;x<=(a1-a2);x++)
{
if(n1.substr(x,a2)==n2)
{
a0+=n1.substring(a3,x);
a0+=n3;
x+=(a2-1);
a3=x+1;
}
}
if(a3<a1)a0+=n1.substring(a3,a1)
{
return a0;
}
}
//轉(zhuǎn)換JavaScript為DHtml
function js2html()
{
hide.value=codes.value
hide.value=commute(hide.value,‘\\"‘,‘"‘);
hide.value=commute(hide.value,‘document.write("‘,‘‘);
hide.value=commute(hide.value,‘")‘,‘‘);
hide.value=commute(hide.value,‘<script>‘,‘‘);
hide.value=commute(hide.value,‘<\/script>‘,‘‘);
outputs.value=hide.value
}
//轉(zhuǎn)換DHtml為JavaScript
function html2js()
{
hide.value=codes.value
hide.value=commute(hide.value,‘"‘,‘\\"‘);
hide.value=commute(hide.value,‘\\‘,‘\\\\‘);
hide.value=commute(hide.value,‘<\/script>‘,‘<\\/script>‘);
outputs.value="<script>document.write(\""+hide.value+"\")<\/script>"
}
//預(yù)覽代碼
function seeHtm()
{
open().document.write("<title>測(cè)試代碼窗口</title>"+outputs.value);
}
//用快捷鍵F12預(yù)覽
document.onkeydown=seeHtms
function seeHtms()
{
if((event.keyCode==123))
{
open().document.write("<title>測(cè)試代碼窗口</title>"+outputs.value);
}
}
//全選代碼
function ta()
{
outputs.select()
}
//拷貝代碼
function tc()
{
document.execCommand("Copy")
}
//粘貼代碼
function tp()
{
outputs.focus()
document.execCommand("Paste")
}
</script>
廣告JS代碼效果大全
1.[普通效果]
    現(xiàn)在很多網(wǎng)站廣告做的如火如荼,現(xiàn)在我就來(lái)介紹一下常見(jiàn)的對(duì)聯(lián)浮動(dòng)廣告效果的代碼使用方法,介紹的這種效果,在1024*768分辨率下正常顯示,在800*600的分辨率下可以自動(dòng)隱藏,以免遮住頁(yè)面影響訪(fǎng)問(wèn)者瀏覽內(nèi)容,下面就是實(shí)現(xiàn)效果所需代碼:


var delta=0.015
var collection;
   
function floaters() {
   
this.items = [];
   
this.addItem =
function(id,x,y,content)
    {
    document.write(‘
<DIV id=+id+‘ style="Z-INDEX: 0; POSITION: absolute; width:80px; height:60px;left:‘+(typeof(x)==‘string‘?eval(x):x)+‘;top:‘+(typeof(y)==‘string‘?eval(y):y)+‘">+content+</DIV>‘);
   
   
var newItem = {};
    newItem.object
= document.getElementById(id);
    newItem.x
= x;
    newItem.y
= y;
   
   
this.items[this.items.length] = newItem;
    }
   
this.play =
function()
    {
    collection
=
this.items
    setInterval(‘play()‘,
10);
    }
    }
   
function play()
    {
   
if(screen.width<=800)
    {
   
for(var i=0;i<collection.length;i++)
    {
    collection.object.style.display
= ‘none‘;
    }
   
return;
    }
   
for(var i=0;i<collection.length;i++)
    {
   
var followObj = collection.object;
   
var followObj_x = (typeof(collection.x)==‘string‘?eval(collection.x):collection.x);
   
var followObj_y = (typeof(collection.y)==‘string‘?eval(collection.y):collection.y);
   
   
if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
   
var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
    dx
=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    followObj.style.left
=followObj.offsetLeft+dx;
    }
   
   
if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
   
var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
    dy
=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
    followObj.style.top
=followObj.offsetTop+dy;
    }
    followObj.style.display
= ‘‘;
    }
    }
   
   
var theFloaters =
new floaters();
    theFloaters.addItem(‘followDiv1‘,‘document.body.clientWidth
-100‘,0,‘</a><br><a href=廣告鏈接地址 target=_blank><img src=廣告圖片地址 width=100 height=400 border=0></a>‘ target=_blank);
    theFloaters.addItem(‘followDiv2‘,
0,0,‘<br><a href=廣告鏈接地址 target=_blank><img src=廣告圖片地址 width=100 height=400 border=0></a>‘ target=_blank);
    theFloaters.play();


把上面的代碼另存為一個(gè)JS文件,然后在想實(shí)現(xiàn)此效果的頁(yè)面用 調(diào)用即可!注意修改廣告圖片地址和連接地址!
廣告JS代碼效果大全 ~~~~~~~~~~

2.[鼠標(biāo)感應(yīng)]
    與前面一個(gè)代碼不同的是,當(dāng)鼠標(biāo)移動(dòng)到廣告圖片上是可以感應(yīng)顯示另外設(shè)置好的廣告大圖效果,下面就是實(shí)現(xiàn)效果所需代碼:

function bigshow(){
    document.all.div_250.style.visibility = ‘visible‘;
    document.all.div_80.style.visibility = ‘hidden‘;
    }
    function bighide(){
    document.all.div_80.style.visibility = ‘visible‘;
    document.all.div_250.style.visibility = ‘hidden‘;
    }
   
    var ad_80= new Array(1);
    var ad_250= new Array(1);
   
    ad_80[0]="<a href=http://www. target=_blank><img src=/skin/adv43/ad/ad_ad.gif border=0></a>";
    ad_250[0]="<a href=http://www. target=_blank><img src=/skin/adv43/ad/ad_ad2.gif border=0></a>";
   
    var imgheight;
    var fubioleft;
    window.screen.width>800 ? fubioleft=15:fubioleft=15
   
    document.write(‘<DIV id=floater_left style="Z-INDEX: 25; LEFT:‘+fubioleft+‘px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px">‘);
   
    ad_now = new Date();
    ad_id= ad_now.getSeconds() %1
   
    var adhead1="<div id=div_80 style=‘position:absolute; width:95px; height:62px; z-index:12‘ onMouseOver=bigshow();>";
    var adhead2="</div><div id=div_250 style=‘position:absolute; visibility: hidden; z-index:13;width: 80; height: 60‘ onMouseOut=bighide();>";
   
    //var adhead1="<div id=div_80 style=‘position:absolute; width:95px; height:62px; z-index:20‘ onMouseOut=‘//MM_showHideLayers(\"div_250\",\"\",\"hide\")‘ onMouseOver=‘MM_showHideLayers(\"div_250\",\"\",\"show\")‘>";
    //var adhead2="</div><div id=div_250 style=‘position:absolute; z-index:21;visibility: hidden; width: 80; height: 60‘ onMouseOver=‘MM_showHideLayers(\"div_250\",\"\",\"show\")‘ onMouseOut=‘MM_showHideLayers(\"div_250\",\"\",\"hide\")‘>";
   
    document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div>");
   
    document.write ("</div>");
    self.onError=null;
    currentX = currentY = 0;
    whichIt = null;
    lastScrollX = 0; lastScrollY = 0;
    NS = (document.layers) ? 1 : 0;
    IE = (document.all) ? 1: 0;
    function heartBeat() {
    if(IE) {
    diffY = document.body.scrollTop;
    diffX = document.body.scrollLeft; }
    if(NS) {
    diffY = self.pageYOffset; diffX = self.pageXOffset; }
    if(diffY != lastScrollY) {
    percent = .5 * (diffY - lastScrollY);
    if(percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);
    if(IE) document.all.floater_left.style.pixelTop += percent;
    if(NS) document.floater_left.top += percent;
    lastScrollY = lastScrollY + percent;
    }
    if(diffX != lastScrollX) {
    percent = .5 * (diffX - lastScrollX);
    if(percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);
    if(IE) document.all.floater_left.style.pixelLeft += percent;
    if(NS) document.floater_left.left += percent;
    lastScrollX = lastScrollX + percent;
    }
    }
   
    if(NS || IE) action = window.setInterval("heartBeat()",1);var ad_80= new Array(1);
    var ad_250= new Array(1);
   
    ad_80[0]="<a href=http://www. target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>";
    ad_250[0]="<a href=http://www. target=_blank><img src=/skin/adv43/ad/ad_ad.jpg border=0></a>";
   
    var imgheight;
    var fubioleft;
    window.screen.width>800 ? fubioleft=15:fubioleft=15
   
    document.write(‘<DIV id=floater_right style="Z-INDEX: 25; LEFT:‘+fubioleft+‘px; WIDTH: 28px;POSITION: absolute; TOP: 42px; HEIGHT: 22px">‘);
   
    ad_now = new Date();
    ad_id= ad_now.getSeconds() %1
   
    function myload()
    {
    if (navigator.appName == "Netscape")
    {
    document.div_right_80.pageX=+window.innerWidth-130;
    document.div_right_250.pageX=+window.innerWidth-300;
    mymove();
    }
    else
    {
    div_right_80.style.left=document.body.offsetWidth-130;
    div_right_250.style.left=document.body.offsetWidth-300;
    mymove();
    }
    }
   
    function mymove()
    {
    if(document.ns)
    {
    document.div_right_80.left=pageXOffset+window.innerWidth-130;
    document.div_right_250.left=pageXOffset+window.innerWidth-300;
    setTimeout("mymove();",20)
    }
    else
    {
    div_right_80.style.left=document.body.scrollLeft+document.body.offsetWidth-145;
    div_right_250.style.left=document.body.scrollLeft+document.body.offsetWidth-300;
    setTimeout("mymove();",20)
    }
    }
   
    var adhead1="<div id=div_right_80 style=‘position:absolute; width:95px; height:60px; z-index:12‘ onMouseOver=bigshow_right();>";
    var adhead2="</div><div id=div_right_250 style=‘position:absolute; visibility: hidden; z-index:13;width: 250; height: 250‘ onMouseOut=bighide_right();><div align=right>";
   
    document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div></div>");
   
    myload()
   
    document.write ("</div>");
    self.onError=null;
    currentX_right = currentY_right = 0;
    whichIt_right = null;
    lastScrollX_right = 0; lastScrollY_right = 0;
    NS = (document.layers) ? 1 : 0;
    IE = (document.all) ? 1: 0;
    function heartBeat_right() {
    if(IE) {
    diffY_right = document.body.scrollTop;
    diffX_right = document.body.scrollLeft; }
    if(NS) {
    diffY_right = self.pageYOffset; diffX_right = self.pageXOffset; }
    if(diffY_right != lastScrollY_right) {
    percent_right = .5 * (diffY_right - lastScrollY_right);
    if(percent_right > 0) percent_right = Math.ceil(percent_right);
    else percent_right = Math.floor(percent_right);
    if(IE) document.all.floater_right.style.pixelTop += percent_right;
    if(NS) document.floater_right.top += percent_right;
    lastScrollY_right = lastScrollY_right + percent_right;
    }
    if(diffX_right != lastScrollX_right) {
    percent_right = .5 * (diffX_right - lastScrollX_right);
    if(percent_right > 0) percent_right = Math.ceil(percent_right);
    else percent_right = Math.floor(percent_right);
    if(IE) document.all.floater_right.style.pixelLeft += percent_right;
    if(NS) document.floater_right.left += percent_right;
    lastScrollX_right = lastScrollX_right + percent_right;
    }
    }
   
    if(NS || IE) action = window.setInterval("heartBeat_right()",1);
    function bigshow_right(){
    document.all.div_right_250.style.visibility = ‘visible‘;
    document.all.div_right_80.style.visibility = ‘hidden‘;
    }
    function bighide_right(){
    document.all.div_right_80.style.visibility = ‘visible‘;
    document.all.div_right_250.style.visibility = ‘hidden‘;
    }document.write(‘‘);
    document.write(‘‘);
    document.write(‘‘);


   
3.[允許關(guān)閉]
    與前面兩個(gè)代碼不同的是,廣告圖下方增加了一個(gè)圖片按紐,允許訪(fǎng)客點(diǎn)擊關(guān)閉廣告圖片,下面文本框中就是實(shí)現(xiàn)效果所需代碼:

var delta=0.015;
    var collection;
    var closeB=false;
    function floaters() {
    this.items = [];
    this.addItem = function(id,x,y,content)
    {
    document.write(‘<DIV id=‘+id+‘ style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:‘+(typeof(x)==‘string‘?eval(x):x)+‘;top:‘+(typeof(y)==‘string‘?eval(y):y)+‘">‘+content+‘</DIV>‘);
   
    var newItem = {};
    newItem.object = document.getElementById(id);
    newItem.x = x;
    newItem.y = y;
   
    this.items[this.items.length] = newItem;
    }
    this.play = function()
    {
    collection = this.items
    setInterval(‘play()‘,30);
    }
    }
    function play()
    {
    if(screen.width<=800 || closeB)
    {
    for(var i=0;i<collection.length;i++)
    {
    collection.object.style.display = ‘none‘;
    }
    return;
    }
    for(var i=0;i<collection.length;i++)
    {
    var followObj = collection.object;
    var followObj_x = (typeof(collection.x)==‘string‘?eval(collection.x):collection.x);
    var followObj_y = (typeof(collection.y)==‘string‘?eval(collection.y):collection.y);
   
    if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
    var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
    dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    followObj.style.left=followObj.offsetLeft+dx;
    }
   
    if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
    var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
    dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
    followObj.style.top=followObj.offsetTop+dy;
    }
    followObj.style.display = ‘‘;
    }
    }
    function closeBanner()
    {
    closeB=true;
    return;
    }
   
    var theFloaters = new floaters();
    //
    theFloaters.addItem(‘followDiv1‘,‘document.body.clientWidth-100‘,0,‘<a  href=http://www. target=_blank><img src=ad/doublead/right.gif width=100 height=554 border=0></a><br><br><img src=ad/doublead/close.gif >‘);
    theFloaters.addItem(‘followDiv2‘,0,0,‘<a  href=http://www. target=_blank><img src=ad/doublead/ad_ad.gif width=100 height=400 border=0 ></a><br><br><img src=ad/doublead/close.gif >‘);
    theFloaters.play();


   把上面的代碼分別另存為兩個(gè)JS文件,然后在想實(shí)現(xiàn)此效果的頁(yè)面用
   
    <script type="text/javascript" language="javascript1.2" src="*.js"></SCRIPT>
   
    調(diào)用即可,*代表你另存的文件名!注意修改廣告圖片地址和連接地址!


廣告JS代碼效果大全 ~~~~~~~~~~

4.[浮動(dòng)對(duì)聯(lián)廣告---之左側(cè)代碼]
   
    如果您想只有一側(cè)顯示的話(huà),下面是實(shí)現(xiàn)左側(cè)效果所需代碼:

  var ad_float_left_src ="圖片地址";
    var ad_float_left_url ="地址";
    var ad_float_left_type = "";
    document.ns = navigator.appName == "Microsoft Internet Explorer"
   
    var imgheight_close
    var imgleft
    window.screen.width>800 ? imgheight_close=120:imgheight_close=120
    window.screen.width>800 ? imgleft=8:imgleft=122
    function myload()
    {
    myleft.style.top=document.body.scrollTop+document.body.offsetHeigh
    t-imgheight_close;
    myleft.style.left=imgleft;
    leftmove();
    }
    function leftmove()
    {
    myleft.style.top=document.body.scrollTop+document.body.offsetHeigh
    t-imgheight_close;
    myleft.style.left=imgleft;
    setTimeout("leftmove();",50)
    }
   
    function MM_reloadPage(init) { //reloads the window if Nav4
    resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&
    (parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
    onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!
    =document.MM_pgH) location.reload();
    }
    MM_reloadPage(true)
   
    function close_float_left(){
    myleft.style.visibility=‘hidden‘;
    }
   
    document.write("<div id=myleft style=‘position:
    absolute;width:80;top:300;left:5;visibility: visible;z-index: 1‘>"
    +"<style>"
    +"A.closefloat:link,A.refloat:visited {text-
    decoration:none;color:#000000;font-size:12px}"
    +"A.closefloat:active,A.refloat:hover {text-decoration:underline;color:#0000FF;font-size:12px}"
    +"</style>"
    +"<table border=0 cellpadding=0 cellspacing=0><tr><td>");
   
    if(document.ns){
    if(ad_float_left_type!="swf")
    document.write("<a href=‘" + ad_float_left_url + "‘ target
    = ‘_blank‘><img src=‘" + ad_float_left_src + "‘ WIDTH=88
    height=31 border=0></a>");
    else
    document.write("<EMBED src=‘" + ad_float_left_src + "‘
    quality=high WIDTH=80 HEIGHT=80 TYPE=‘a(chǎn)pplication/x-shockwave-
    flash‘ id=changhongout ></EMBED>");
   
    document.write("</td></tr><tr><td width=80 height=20
    align=right><a href=‘javascript:close_float_left( target=_blank);void(0);‘
    class=closefloat><b><font color=#ff0000>關(guān)閉</font></b></a></td></tr>"
    +"</table>"
    +"</div>");
   
    myload()}



   
[ 5.背投廣告]

<script language="javascript">
    <!--
    var sohu=window.open(‘http://www.sohu.com‘);
    var ads=window.open(‘a(chǎn)bout:blank‘,‘a(chǎn)ds‘,‘width=700,height=400‘);
    sohu.focus();
    ads.document.open();
    ads.document.write ("<html><head><title>ads</title></head><body>This is background ads</body></html>");
    ads.document.close();
    //-->
    </script>
   


[ 6.收縮廣告]
   
    <script language="javascript">
    <!--
    var bwidth=800;
    var bheight=400;
    function go() {
    bwidth = bwidth - 10;
    bheight = bheight - 5;
    if(bwidth <= 10)
    { ads.style.display=‘none‘;clearTimeout("my"); }
    else
    { ads.outerHTML=‘<span id="ads" style="width:‘+bwidth+‘px;height:‘+bheight+‘px;background-color:#0099FF;"></span>‘;}
    var my=setTimeout("go()",50);
    }
    setTimeout("go()",6000);
    //-->
    </script>
    <body topmargin="0" leftmargin="0">
    <div align="center"><span id="ads" style="width:800px;height:400px;background-color:#0099FF"></span></div>
    </body>

******************************************************************************
    把上面的代碼另存為三個(gè)*.JS文件,然后在想實(shí)現(xiàn)此效果的頁(yè)面用
     
    CODE:
    <script src="*.js"></SCRIPT>
   
    調(diào)用即可,*代表你另存的文件名!注意修改廣告圖片地址和連接地址!相應(yīng)的參數(shù)可以根據(jù)頁(yè)面自行調(diào)整

js幻燈片播放器~~~~~~~~~~

var _c = 0;
var _i = 0;
var _v = 0;
var _l = 0;
var _sf = 3000;
var _html = null;
var _image = null;
var _mycars= new Array();
var _w = new Array();
var _h = new Array();

function adRotator() {}

function adRotator.add(p,w,h)
{
   _mycars[_c] = p;
   _w[_c] = w;
   _h[_c] = h;
   _c = _c + 1;
}

/* 播放設(shè)置 */
function  adRotator.loads()
{
   if (_i < _mycars.length && _l < 1)
   {
     _html = ‘<img src="‘ + _mycars[_i] + ‘" width="‘ + _w[_i] + ‘" height="‘ + _h[_i] + ‘" style="border:1px solid #CCCCCC;">‘
     if (_v < 1)
     {
        document.getElementById(‘image‘).value = _html + ‘,‘ + _i;
        document.getElementById(‘rotatorPlayer‘).innerHTML = _html;
        _i = _i + 1;
  document.getElementById(‘backs‘).disabled=‘‘;
        window.setTimeout("adRotator.loads("+_i+")",_sf);
     }
   }
   else
   {
     _html = ‘<img src="‘ + _mycars[_i] + ‘" width="‘ + _w[_i] + ‘" height="‘ + _h[_i] + ‘" style="border:1px solid #CCCCCC;">‘
  document.getElementById(‘image‘).value = _html + ‘,‘ + _i;
     document.getElementById(‘rotatorPlayer‘).innerHTML = _html;
   }
   if (_i+1 > _mycars.length)
   {
      document.getElementById(‘stops‘).disabled=‘True‘;
   document.getElementById(‘play‘).disabled=‘‘;
   document.getElementById(‘backs‘).disabled=‘‘;
   document.getElementById(‘next‘).disabled=‘True‘;
   _i = 0;
   _v = 1;
   }
}

/* 播放 */
function  adRotator.play()
{
   _v = 0;
   _l = 0;
   adRotator.loads();
}

/* 下一張 */
function adRotator.next()
{
   _l = 1;
   if(_i+1 < _mycars.length)
   {
      _i = _i + 1;
   document.getElementById(‘play‘).disabled=‘‘;
   document.getElementById(‘stops‘).disabled=‘True‘;
   document.getElementById(‘backs‘).disabled=‘‘;
   adRotator.loads();
   }
   else
   {
      document.getElementById(‘next‘).disabled=‘True‘;
   }
}

/* 上一張 */
function adRotator.backs()
{
   _l = 1;
   if(_i-1 < 0)
   {
      document.getElementById(‘backs‘).disabled=‘True‘;
   }
   else
   {
      _i = _i - 1;
   document.getElementById(‘play‘).disabled=‘‘;
   document.getElementById(‘stops‘).disabled=‘True‘;
   document.getElementById(‘next‘).disabled=‘‘;
   adRotator.loads();
   }
}

/* 間隔時(shí)間 */
function adRotator.set()
{
   var _sfc = document.getElementById(‘second‘).value;
   if (isInteger(_sfc))
   {
     _sf = _sfc * 1000;
   }
   else
   {
     alert(‘提示:只能輸入數(shù)字!‘);
     document.getElementById(‘second‘).value=1;
     document.getElementById(‘second‘).select();
   }
}

/* 字符檢測(cè) */
function isInteger(str)
{  
  var regu = /^[-]{0,1}[0-9]{1,}$/;
  return regu.test(str);
}

/* 暫停 */
function adRotator.stops()
{
   _v = 1;
}

/* 添加圖片,還要加的話(huà)注意圖片名字就好了,后面400,300是大小 */
adRotator.add("1.jpg",400,300);
adRotator.add("2.jpg",400,300);
adRotator.add("3.jpg",400,300);


把以上文件存為一個(gè)JS文件

在下面文件中引用即可

<style type="text/css">
<!--
body { font-size:12px;
}
input {
    border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
button {
    border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
-->
</style>
<script language="javascript" src="test.js">
</script>

     
<body >
<div id="rotatorPlayer"></div>



<input type="button" name="play" value="開(kāi)始播放"  disabled="True"/>
<input type="button" name="stops" value="暫停" />
<input type="button" name="backs" value="上一張"  disabled="true"/>
<input type="button" name="next" value="下一張" />   
<input type="text" id="second" value="3" size="3" maxlength="2">

<input type="button" value="設(shè)置時(shí)間"  />



<input name="image" type="text" size="65"/>


一個(gè)非常棒的播放器,可惜如果圖片是非常大的話(huà),那結(jié)果有點(diǎn)慘!


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1902826

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多