200多個js技巧代碼(六)

來源:互聯網
上載者:User

179.【檔案(F)】菜單中的命令的實現1、〖開啟〗命令的實現[格式]:document.execCommand("open")[說明]這跟VB等編程設計中的webbrowser控制項中的命令有些相似,大家也可依此琢磨琢磨。[舉例]在<body></body>之間加入:<a href="###" onclick=document.execCommand("open")>開啟</a>2、〖使用 記事本 編輯〗命令的實現[格式]:location.replace("view-source:"+location)[說明]開啟記事本,在記事本中顯示該網頁的原始碼。[舉例]在<body></body>之間加入:<a href="###" onclick=location.replace("view-source:"+location)>使用 記事本編輯</a>3、〖另存新檔〗命令的實現[格式]:document.execCommand("saveAs")[說明]將該網頁儲存到本地碟的其它目錄![舉例]在<body></body>之間加入:<a href="###" onclick=document.execCommand("saveAs")>另存新檔</a>4、〖列印〗命令的實現[格式]:document.execCommand("print")[說明]當然,你必須裝了印表機![舉例]在<body></body>之間加入:<a href="###" onclick=document.execCommand("print")>列印</a>5、〖關閉〗命令的實現[格式]:window.close();returnfalse[說明]將關閉本視窗。[舉例]在<body></body>之間加入:<a href="###" onclick=window.close();returnfalse)>關閉本視窗</a>180.【編輯(E)】菜單中的命令的實現〖全選〗命令的實現[格式]:document.execCommand("selectAll")[說明]將選種網頁中的全部內容![舉例]在<body></body>之間加入:<a href="###" onclick=document.execCommand("selectAll")>全選</a>181.【查看(V)】菜單中的命令的實現1、〖重新整理〗命令的實現[格式]:location.reload() 或 history.go(0)[說明]瀏覽器重新開啟本頁。[舉例]在<body></body>之間加入:<a href="###" onclick=location.reload()>重新整理</a>或加入:<a href="###" onclick=history.go(0)>重新整理</a>2、〖源檔案〗命令的實現[格式]:location.replace("view-source:"+location)[說明]查看該網頁的原始碼。[舉例]在<body></body>之間加入:<a href="###" onclick=location.replace("view-source:"+location)>查看源檔案</a>3、〖全螢幕顯示〗命令的實現[格式]:window.open(document.location, "url", "fullscreen")[說明]全螢幕顯示本頁。[舉例]在<body></body>之間加入:<a href="###" onclick=window.open(document.location,"url","fullscreen")>全螢幕顯示</a>182.【收藏(A)】菜單中的命令的實現1、〖添加到收藏夾〗命令的實現[格式]:window.external.AddFavorite('url', '“網站名”)[說明]將本頁添加到收藏夾。[舉例]在<body></body>之間加入:<a href="javascript:window.external.AddFavorite('http://oh.jilinfarm.com', '胡明新的個人首頁')">添加到收藏夾</a>2、〖整理收藏夾〗命令的實現[格式]:window.external.showBrowserUI("OrganizeFavorites",null)[說明]開啟整理收藏夾對話方塊。[舉例]在<body></body>之間加入:<a href="###" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a>183.【工具(T)】菜單中的命令的實現〖internet選項〗命令的實現[格式]:window.external.showBrowserUI("PrivacySettings",null)[說明]開啟internet選項對話方塊。[舉例]在<body></body>之間加入:<a href="###" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項</a>184.【工具列】中的命令的實現1、〖前進〗命令的實現[格式]history.go(1) 或 history.forward()[說明]瀏覽器開啟後一個頁面。[舉例]在<body></body>之間加入:<a href="###" onclick=history.go(1)>前進</a>或加入:<a href="###" onclick=history.forward()>前進</a>2、〖後退〗命令的實現[格式]:history.go(-1) 或 history.back()[說明]瀏覽器返回上一個已瀏覽的頁面。[舉例]在<body></body>之間加入:<a href="###" onclick=history.go(-1)>後退</a>或加入:<a href="###" onclick=history.back()>後退</a>3、〖重新整理〗命令的實現[格式]:document.reload() 或 history.go(0)[說明]瀏覽器重新開啟本頁。[舉例]在<body></body>之間加入:<a href="###" onclick=location.reload()>重新整理</a>或加入:<a href="###" onclick=history.go(0)>重新整理</a>185.其它命令的實現〖定時關閉本視窗〗命令的實現[格式]:settimeout(window.close(),關閉的時間)[說明]將關閉本視窗。[舉例]在<body></body>之間加入:<a href="###" onclick=settimeout(window.close(),3000)>3秒關閉本視窗</a>【附】為了方便讀者,下面將列出所有執行個體代碼,你可以把它們放到一個html檔案中,然後預覽效果。<a href="###" onclick=document.execCommand("open")>開啟</a><br><a href="###" onclick=location.replace("view-source:"+location)>使用 記事本編輯</a><br><a href="###" onclick=document.execCommand("saveAs")>另存新檔</a><br><a href="###" onclick=document.execCommand("print")>列印</a><br><a href="###" onclick=window.close();returnfalse)>關閉本視窗</a><br><a href="###" onclick=document.execCommand("selectAll")>全選</a><br><a href="###" onclick=location.reload()>重新整理</a><a href="###" onclick=history.go(0)>重新整理</a><br><a href="###" onclick=location.replace("view-source:"+location)>查看源檔案</a><br><a href="###" onclick=window.open(document.location,"url","fullscreen")>全螢幕顯示</a><br><a href="javascript:window.external.AddFavorite('http://homepage.yesky.com', '天極網頁陶吧')">添加到收藏夾</a><br><a href="###" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夾</a><br><a href="###" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet選項</a><br><a href="###" onclick=history.go(1)>前進1</a> <a href="###" onclick=history.forward()>前進2</a><br><a href="###" onclick=history.go(-1)>後退1</a> <a href="###" onclick=history.back()>後退2</a><br><a href="###" onclick=settimeout(window.close(),3000)>3秒關閉本視窗</a><br>186.給DHTML中的標籤添加一個新的屬性,可以隨意加<BODY onload="alert(a1.epass)"><input type=text name="a1" epass="zhongguo"></BODY>//187.xmlhttp技術<BODY> 此方法是通過XMLHTTP對象從伺服器擷取XML文檔,樣本如下。 <input type=button value="載入XML文檔" onclick="getData('data.xml')"><script language="JavaScript"> function getDatal(url){ var xmlhttp =new ActiveXObject("Microsoft.XMLHTTP");//建立XMLHTTPRequest對象 xmlhttp.open("GET",url,false,"","");//使用HTTP GET初始化HTTP請求 xmlhttp.send("");//發送HTTP請求並擷取HTTP響應return xmlhttp.responseXML;//擷取XML文檔 } </script ></BODY>//188.伺服器端通過request.getReader()獲得傳入的字串189.在java中使用Regexjava.util.regex.Pattern p =java.util.regex.Pattern.compile("\\d+|.\\d+|\\d+.\\d*|(E|\\d+E|.\\d+E|\\d+.\\d*E)((\\+|-)\\d|\\d)\\d*");java.util.regex.Matcher m = p.matcher("12.E+3");boolean result = m.matches();//190.給下拉框分組<SELECT><OPTGROUP LABEL="堿性金屬"><OPTION>鋰 (Li)</OPTION><OPTION>納 (Na)</OPTION><OPTION>鉀 (K)</OPTION></OPTGROUP><OPTGROUP LABEL="鹵素"><OPTION>氟 (F)</OPTION><OPTION>氯 (Cl)</OPTION><OPTION>溴 (Br)</OPTION></OPTGROUP></SELECT>//191.加註音<RUBY>基準文本<RT>注音文本</RUBY>//192.加刪除線<S>此文本將帶刪除線顯示。</S>//193.取frame中的event事件document.frames("workspace").event.keyCode//194.是彈出方法的定義String.prototype.trim=function(){ returnthis.replace(/(^\s*)|(\s*$)/g, "");}alert("".trim)//195.防止網頁被包含if (window != window.top)top.location.href = location.href;//196.讓網頁一直在frame裡面if(window==window.top){ document.body.innerHTML="<center><h1>請通過正常方式訪問本頁面!</h1></center>"; //window.close();}//197.加為首頁<SCRIPT>function fnSet(){oHomePage.setHomePage(location.href);event.returnValue =false;}</SCRIPT><IE:HOMEPAGE ID="oHomePage" style="behavior:url(#default#homepage)"/>//198.xml資料島操作<HTML><HEAD><Title>HTML中的資料島中的記錄集</Title></HEAD><body bkcolor=#EEEEEE text=blue bgcolor="#00FFFF"><Table align=center width="100%"><TR><TD align="center"><h5><b><font size="4" color="#FF0000">HTML中的XML資料島記錄編輯與添加    </font></b></h5></TD></TR></Table><HR>  酒店名稱:<input type=text datasrc=#theXMLisland DataFLD=NAME size="76"><BR>  地址:<input type=text datasrc=#theXMLisland DataFLD=Address size="76"><BR>  首頁:<input type=text datasrc=#theXMLisland DataFLD=HomePage size="76"><BR>  電子郵件:<input type=text datasrc=#theXMLisland DataFLD=E-Mail size="76"><BR>  電話:<input type=text datasrc=#theXMLisland DataFLD=TelePhone size="76"><BR>  層級:<input type=text datasrc=#theXMLisland DataFLD=Grade size="76"><HR><input id="first" TYPE=button value="<< 第一條記錄"     onclick="theXMLisland.recordset.moveFirst()"><input id="prev" TYPE=button value="<上一條記錄"   onclick="theXMLisland.recordset.movePrevious()"><input id="next" TYPE=button value="下一條記錄>" onclick="theXMLisland.recordset.moveNext()"><input id="last" TYPE=button value="最後一條記錄>>" onclick="theXMLisland.recordset.moveLast()">&nbsp;   <input id="Add" TYPE=button value="添加新記錄" onclick="theXMLisland.recordset.addNew()"><XML ID="theXMLisland"><HotelList><Hotel><Name>四海大酒店</Name><Address>海魂路1號</Address><HomePage>www.sihaohotel.com.cn</HomePage><E-Mail>master@sihaohotel.com.cn</E-Mail><TelePhone>(0989)8888888</TelePhone><Grade>五星級</Grade></Hotel><Hotel><Name>五湖賓館</Name><Address>東平路99號</Address><HomePage>www.wuhu.com.cn</HomePage><E-Mail>web@wuhu.com.cn</E-Mail><TelePhone>(0979)1111666</TelePhone><Grade>四星級</Grade></Hotel><Hotel><Name>“大沙漠”賓館</Name><Address>留香路168號</Address><HomePage>www.dashamohotel.com.cn</HomePage><E-Mail>master@dashamohotel.com.cn</E-Mail><TelePhone>(0989)87878788</TelePhone><Grade>五星級</Grade></Hotel><Hotel><Name>“畫眉鳥”大酒店</Name><Address>血海飄香路2號</Address><HomePage>www.throstlehotel.com.cn</HomePage><E-Mail>chuliuxiang@throstlehotel.com.cn</E-Mail><TelePhone>(099)9886666</TelePhone><Grade>五星級</Grade></Hotel></HotelList></XML></body></HTML>//xml資料島中添加記錄

 

 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.