您的位置:首页 > Web前端 > JavaScript

200多个js技巧代码(七)

2012-11-25 10:25 337 查看
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();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)】菜单中的命令的实现

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>
<a href="###" onclick=location.replace("view-source:"+location)>使用 记事本编辑</a>
<a href="###" onclick=document.execCommand("saveAs")>另存为</a>
<a href="###" onclick=document.execCommand("print")>打印</a>
<a href="###" onclick=window.close();return false)>关闭本窗口</a>
<a href="###" onclick=document.execCommand("selectAll")>全选</a>
<a href="###" onclick=location.reload()>刷新</a> <a href="###" onclick=history.go(0)>刷新</a>
<a href="###" onclick=location.replace("view-source:"+location)>查看源文件</a>
<a href="###" onclick=window.open(document.location,"url","fullscreen")>全屏显示</a>
<a href="javascript:window.external.AddFavorite('http://homepage.yesky.com', '天极网页陶吧')">添加到收藏

夹</a>
<a href="###" onclick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a>
<a href="###" onclick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a>
<a href="###" onclick=history.go(1)>前进1</a> <a href="###" onclick=history.forward()>前进2</a>
<a href="###" onclick=history.go(-1)>后退1</a> <a href="###" onclick=history.back()>后退2</a>
<a href="###" onclick=settimeout(window.close(),3000)>3秒关闭本窗口</a>

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">
地址:<input type=text datasrc=#theXMLisland DataFLD=Address size="76">
主页:<input type=text datasrc=#theXMLisland DataFLD=HomePage size="76">
电子邮件:<input type=text datasrc=#theXMLisland DataFLD=E-Mail size="76">
电话:<input type=text datasrc=#theXMLisland DataFLD=TelePhone size="76">
级别:<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数据岛中添加记录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: