Javascript常用107個技巧

來源:互聯網
上載者:User
1.document.write( " "); 輸出語句 2.JS中的注釋為// 3.傳統的HTML文檔順序是:document- >html- >(head,body) 4.一個瀏覽器視窗中的DOM順序是:window- >(navigator,screen,history,location,document) 5.得到表單中元素的名稱和值:document.getElementById( "表單中元素的ID號 ").name(或value) 6.一個小寫轉大寫的JS: document.getElementById( "output ").value = document.getElementById( "input ").value.toUpperCase(); 7.JS中的實值型別:String,Number,Boolean,Null,Object,Function 8.JS中的字元型轉換成數值型:parseInt(),parseFloat() 9.JS中的數字轉換成字元型:( " " 變數) 10.JS中的取字串長度是:(length) 11.JS中的字元與字元相串連使用 號. 12.JS中的比較操作符有:==等於,!=不等於, >, >=, <. expression loop functionname var form="window.document.forms[0]" for i="0;" if form.elements.value=" " mystring="new" string is lightsword value1 today="new" date :> 49.引用一個檔案式的JS:  50.指定在不支援指令碼的瀏覽器顯示的HTML:   51.當超鏈和onCLICK事件都有時,則老版本的瀏覽器轉向a.html,否則轉向b.html.例: dfsadf  52.JS的內建對象 有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeErr or,URIError 53.JS中的換行:\n 54.視窗全屏大小:  55.JS中的all代表其下層的全部元素 56.JS中的焦點順序:document.getElementByid( "表單元素 ").tabIndex = 1 57.innerHTML的值是表單元素的值:如 

"how are you "

,則innerHTML的值就是:how are you 58.innerTEXT的值和上面的一樣,只不過不會把 這種標記顯示出來. 59.contentEditable可設定元素是否可被修改,isContentEditable返回是否可修改的狀態. 60.isDisabled判定是否為禁止狀態.disabled設定禁止狀態 61.length取得長度,返回整型數值 62.addBehavior()是一種JS調用的外部函數檔案其副檔名為.htc 63.window.focus()使當前的視窗在所有視窗之前. 64.blur()指失去焦點.與FOCUS()相反. 65.select()指元素為選中狀態. 66.防止使用者對文字框中輸入文本: 67.取出該元素在頁面中出現的數量:document.all.tags( "div(或其它HTML標記符) ").length 68.JS中分為兩種表單輸出:模態和非模態.window.showModaldialog(),window.showModeless() 69.狀態欄文字的設定:window.status= '文字 ',預設的狀態欄文字設定:window.defaultStatus = '文字. '; 70.添加到收藏夾:external.AddFavorite( "http://www.dannyg.com ";, "jaskdlf "); 71.JS中碰到指令碼錯誤時不做任何操作:window.onerror = doNothing; 指定錯誤控制代碼的文法為:window.onerror = handleError; 72.JS中指定當前開啟視窗的父視窗:window.opener,支援opener.opener...的多重繼續. 73.JS中的self指的是當前的視窗 74.JS中狀態欄顯示內容:window.status= "內容 " 75.JS中的top指的是框架組中最頂層的架構 76.JS中關閉當前的視窗:window.close(); 77.JS中提出是否確認的框:if(confirm( "Are you sure? ")){alert( "ok ");}else{alert( "Not Ok ");} 78.JS中的視窗重新導向:window.navigate( "http://www.sina.com.cn ";); 79.JS中的列印:window.print() 80.JS中的提示輸入框:window.prompt( "message ", "defaultReply "); 81.JS中的視窗捲軸:window.scroll(x,y) 82.JS中的視窗滾動到位置:window.scrollby 83.JS中設定時間間隔:setInterval( "expr ",msecDelay)或setInterval(funcRef,msecDelay)或setTimeout 84.JS中的模態顯示在IE4 行,在NN中不行:showModalDialog( "URL "[,arguments][,features]); 85.JS中的退出之前使用的控制代碼:function verifyClose(){event.returnValue= "we really like you and hope you will stay longer. ";}} window.=verifyClose; 86.當表單第一次調用時使用的檔案控制代碼:onload() 87.當表單關閉時調用的檔案控制代碼:onunload() 88.window.location的屬性: protocol(http:),hostname(www.example.com),port(80),host(www.example.com:80),pathname ( "/a/a.html "),hash( "#giantGizmo ",指跳轉到相應的錨記),href(全部的資訊) 89.window.location.reload()重新整理當前頁面. 90.window.history.back()返回上一頁,window.history.forward()返回下一頁,window.history.go(返回第幾頁,也可以使用訪問過的URL) 91.document.write()不換行的輸出,document.writeln()換行輸出 92.document.body.noWrap=true;防止連結文字折行. 93.變數名.charAt(第幾位),取該變數的第幾位的字元. 94. "abc ".charCodeAt(第幾個),返回第幾個字元的ASCii碼值. 95.字串串連:string.concat(string2),或用 =進行串連 96.變數.indexOf( "字元 ",起始位置),返回第一個出現的位置(從0開始計算) 97.string.lastIndexOf(searchString[,startIndex])最後一次出現的位置. 98.string.match(regExpression),判定字元是否匹配. 99.string.replace(regExpression,replaceString)替換現有字串. 100.string.split(分隔字元)返回一個數組儲存值. 101.string.substr(start[,length])取從第幾位到指定長度的字串. 102.string.toLowerCase()使字串全部變為小寫. 103.string.toUpperCase()使全部字元變為大寫. 104.parseInt(string[,radix(代表進位)])強制轉換成整型. 105.parseFloat(string[,radix])強制轉換成浮點型. 106.isNaN(變數):測試是否為數值型. 107.定義常量的要害字:const,定義變數的要害字:var
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.