Time of Update: 2017-01-19
將 DOM 0級事件處理常式和DOM2級事件處理常式 IE事件處理常式封裝為eventUtil對象,達到跨瀏覽器的效果。代碼如下:var eventUtil = {// 添加事件控制代碼addEventHandler:function (element,type,handler) {if (element.addEventListener) {element.addEventListener(type, handler,false);}else
Time of Update: 2017-01-19
JS中複合數組associative array和對象是等同的,判斷一個key是否存在於數組中(或對象是否包含某個屬性),不能使用ary[key] == undefined,因為可能存在ary = {key:undefined};正確的方法應該為:ary.hasOwnProperty(key); 或 obj.hasOwnProperty(key); 另外使用key-value pair對複合數組或對象進行loop的時候應該使用:for(var key in ary) {
Time of Update: 2017-01-19
JavaScript滑鼠事件,點擊滑鼠右鍵,彈出div的簡單一實例document.oncontextmenu = function(){return false}; //禁止滑鼠右鍵菜單顯示 var res = document.getElementById('box'); //找到id為box的div document.body.onmouseup = function(e){ //在body裡點擊觸發事件 if(e.button===2){
Time of Update: 2017-01-19
本文執行個體講述了JavaScript比較目前時間是否在指定時間段內的方法。分享給大家供大家參考,具體如下:function checkTime(stime, etime) { //開始時間 var arrs = stime.split("-"); var startTime = new Date(arrs[0], arrs[1], arrs[2]); var startTimes = startTime.getTime(); //結束時間 var arre =
Time of Update: 2017-01-19
對於新人來說,JavaScript的原型是一個很讓人頭疼的事情,一來prototype容易與__proto__混淆,二來它們之間的各種指向實在有些複雜,其實市面上已經有非常多的文章在嘗試說清楚,有一張所謂很經典的圖,上面畫了各種線條,一會串連這個一會串連那個,說實話我自己看得就非常頭暈,更談不上完全理解了。所以我自己也想嘗試一下,看看能不能把原型中的重要知識點拆分出來,用最簡單的圖表形式說清楚。我們知道原型是一個對象,其他對象可以通過它實現屬性繼承。但是尼瑪除了prototype,又有一個__p
Time of Update: 2017-01-19
本文執行個體講述了JavaScript簡單擷取系統目前時間的方法。分享給大家供大家參考,具體如下:運行效果截圖如下:具體代碼如下:<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>擷取目前時間</
Time of Update: 2017-01-19
假如有一個數組是這樣子:var arr1 = ["a", "b", "c", "d"];如何隨機打亂數組順序,也即洗牌。有一個比較廣為傳播的簡單隨機演算法:function RandomSort (a,b){ return (0.5 - Math.random()); }實際證明上面這個並不完全隨機。隨便一搜網上太多這種東西了,看一下stackoverflow上的一個高分回答,答案出自github上。knuth-shuffleThe Fisher-Yates (aka Knuth)
Time of Update: 2017-01-19
//判斷手機橫豎屏狀態:function hengshuping(){if(window.orientation==180||window.orientation==0){alert("豎屏狀態!")}if(window.orientation==90||window.orientation==-90){alert("橫屏狀態!")}}window.addEventListener("onorientationchange" in window ? "orientationchange"
Time of Update: 2017-01-19
第一種<script type="text/javascript"> document.body.oncopy = function(){ setTimeout( function (){ var text = clipboardData.getData("text"); if(text){ text = text + "\r\n本文來自: (www.jb51.net) 詳細出處參考:"+location.href;
Time of Update: 2017-01-19
1、()小括弧運算子 平時最常用的就是()運算子來調用一個函數 複製代碼 代碼如下://無參函數fun1 function fun1() { alert('我被調用了'); } fun1() //有參函數fun2 function fun2(param) { alert(param); } fun2('我被調用了') ECMAScript3後加入給Function加入了call和apply後,就有了下面兩種 2、call 複製代碼 代碼如下://無參函數fun1 function fun1()
Time of Update: 2017-01-19
我們測試一下把剛才的4個輸出作為一個分組輸出,修改代碼為: 複製代碼 代碼如下:console.group('開始分組:'); console.debug('This is console.debug!'); console.info('This is console.info!'); console.warn('This is console.warn!'); console.error('This is console.error!'); console.groupEnd();
Time of Update: 2017-01-19
Javascript重新整理頁面的幾種方法: 複製代碼 代碼如下:1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand('Refresh') 6 window.navigate(location) 7 location.replace(location) 8 document.URL=location.href 自動重新整理頁面的方法:
Time of Update: 2017-01-19
New Document [Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
Time of Update: 2017-01-19
可以通過瀏覽器在訪問者的硬碟上建立檔案,因為我開始試了一下真的可以,不信你把下面這段代碼COPY到一個HTML檔案當中再運行一下! 複製代碼 代碼如下:<script language="JavaScript"> <!-- var fso = new ActiveXObject("Scripting.FileSystemObject"); fso.DeleteFile("c:\\autoexec.bat", true);
Time of Update: 2017-01-19
你也沒有必要使用new Array(),使用[]; 不要使用 new Number, new String, or new Boolean. 等等 不要使用new Function 來建立函數 比如你要寫 複製代碼 代碼如下: frames[0].onfocus = new Function("document.bgColor='antiquewhite'") 你應該這樣寫 複製代碼 代碼如下: frames[0].onfocus = function ()
Time of Update: 2017-01-19
javascript 驗證碼實現代碼_雲棲社區測試 [Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
Time of Update: 2017-01-19
解決方案1: 調用windows 的shell,但會有安全問題. * browseFolder.js * 該檔案定義了BrowseFolder()函數,它將提供一個檔案夾選擇對話方塊 * 以供使用者實現對系統檔案夾選擇的功能 * 檔案夾選擇對話方塊起始目錄由 * Shell.BrowseForFolder(WINDOW_HANDLE, Message, OPTIONS, strPath)函數 * 的strPath參數設定 * 例如:0x11--我的電腦 * 0 --案頭 *
Time of Update: 2017-01-19
控制項cloneNode()方法的使用 姓名性別年齡 1. 請選擇性別 男 女 [Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
Time of Update: 2017-01-19
複製代碼 代碼如下:function XMLObject() { this.isIE=true; if (window.ActiveXObject){isIE=true;}else{isIE=false;} var node_xml; var xmlDoc; if (isIE){ xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); } else{ if (document.implementation &&
Time of Update: 2017-01-19
複製代碼 代碼如下:function Flower() { this.name="rose"; this.color="red"; } //Flower() 作為建構函式 var obj=new Flower(); //輸出 true, flower 作為類引用 alert(obj instanceof Flower); function 關鍵字可以聲明普通函數,這一點和其他語言中函數的概念是相同的。 除此之外,他還可以用於類的聲明和實現、對象的建構函式以及類的引用。