200多個js技巧代碼(7)

179.【文件(F)】菜單中的命令的實現

一、〖打開〗命令的實現
[格式]:document.execCommand("open")
[說明]這跟VB等編程設計中的webbrowser控件中的命令有些類似,你們也可依此琢磨琢磨。
[舉例]在<body></body>之間加入:
<a href="###" onclick=document.execCommand("open")>打開</a>

二、〖使用 記事本 編輯〗命令的實現
[格式]:location.replace("view-source:"+location)
[說明]打開記事本,在記事本中顯示該網頁的源代碼。
[舉例]在<body></body>之間加入:
<a href="###" onclick=location.replace("view-source:"+location)>使用 記事本編輯</a>

三、〖另存爲〗命令的實現
[格式]:document.execCommand("saveAs")
[說明]將該網頁保存到本地盤的其它目錄!
[舉例]在<body></body>之間加入:
<a href="###" onclick=document.execCommand("saveAs")>另存爲</a>

四、〖打印〗命令的實現
[格式]:document.execCommand("print")
[說明]固然,你必須裝了打印機!
[舉例]在<body></body>之間加入:
<a href="###" onclick=document.execCommand("print")>打印</a>

五、〖關閉〗命令的實現
[格式]:window.close();return false
[說明]將關閉本窗口。
[舉例]在<body></body>之間加入:
<a href="###" onclick=window.close();return false)>關閉本窗口</a>

180.【編輯(E)】菜單中的命令的實現

〖全選〗命令的實現
[格式]:document.execCommand("selectAll")
[說明]將選種網頁中的所有內容!
[舉例]在<body></body>之間加入:
<a href="###" onclick=document.execCommand("selectAll")>全選</a>

181.【查看(V)】菜單中的命令的實現

一、〖刷新〗命令的實現
[格式]:location.reload() 或 history.go(0)
[說明]瀏覽器從新打開本頁。
[舉例]在<body></body>之間加入:
<a href="###" onclick=location.reload()>刷新</a>
或加入:
<a href="###" onclick=history.go(0)>刷新</a>

二、〖源文件〗命令的實現
[格式]:location.replace("view-source:"+location)
[說明]查看該網頁的源代碼。
[舉例]在<body></body>之間加入:
<a href="###" onclick=location.replace("view-source:"+location)>查看源文件</a>

三、〖全屏顯示〗命令的實現
[格式]:window.open(document.location, "url", "fullscreen")
[說明]全屏顯示本頁。
[舉例]在<body></body>之間加入:
<a href="###" onclick=window.open(document.location,"url","fullscreen")>全屏顯示</a>

182.【收藏(A)】菜單中的命令的實現

一、〖添加到收藏夾〗命令的實現
[格式]:window.external.AddFavorite('url', '「網站名」)
[說明]將本頁添加到收藏夾。
[舉例]在<body></body>之間加入:
<a href="javascript:window.external.AddFavorite('http://oh.jilinfarm.com', '胡明新的我的主頁')">添加到收

藏夾</a>

二、〖整理收藏夾〗命令的實現
[格式]: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.【工具欄】中的命令的實現

一、〖前進〗命令的實現
[格式]history.go(1) 或 history.forward()
[說明]瀏覽器打開後一個頁面。
[舉例]在<body></body>之間加入:
<a href="###" onclick=history.go(1)>前進</a>
或加入:
<a href="###" onclick=history.forward()>前進</a>

二、〖後退〗命令的實現
[格式]:history.go(-1) 或 history.back()
[說明]瀏覽器返回上一個已瀏覽的頁面。
[舉例]在<body></body>之間加入:
<a href="###" onclick=history.go(-1)>後退</a>
或加入:
<a href="###" onclick=history.back()>後退</a>

三、〖刷新〗命令的實現
[格式]: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();return false)>關閉本窗口</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中使用正則表達式
java.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()
{
 return this.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()">  
  <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數據島中添加記錄
相關文章
相關標籤/搜索