70种简单常用的JS代码
1、后退 前进
<input type="button" value="后退" onClick="history.go(-1)"> <input type="button" value="前进" onClick="history.go( 1 );return true;">
2、返回
<form><input type="button" value="返回上一步" onClick="history.back(-1)"></form>
3、查看源码
<input type="button" name="view" value="查看源码"
onClick="window.location="view-source:" +window.location.href"> 4、禁止查看源码
<body oncontextmenu="return false"></body> 5、刷新按钮一
<input type="button" value="刷新按钮一" onClick="ReloadButton()"> <script>function
ReloadButton(){location.href="i001.htm";}</script>
刷新按钮二
<input type="button" value="刷新按钮二" onClick="history.go(0)"> 6、回首页按钮
<input type="button" value="首页" onClick="HomeButton()"> <script>function
HomeButton(){location.href=http://www.winliuxq.com;}</script> 7、弹出警告框
<input type="button" value="弹出警告框" onClick="AlertButton()"> <script>function AlertButton(){window.alert("要多多光临呀!");}</script>
8、状态栏信息
<input type="button" value="状态栏信息" onClick="StatusButton()">
<script>function StatusButton(){window.status="要多多光临呀!";}</script>
9、背景色变换
<form><input type="button" value="背景色变换"
onClick="BgButton()"></form> <script>function BgButton(){
if (document.bgColor==’#00ffff’) {document.bgColor=’#ffffff’;} else{document.bgColor=’#00ffff’;} }
</script>
10、打开新窗口
<input type="button" value="打开新窗口" onClick="NewWindow()"> <script>function
NewWindow(){window.open("c01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");} </script>
11、窗口最小化
<OBJECT id="min" type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><PARAM
name="Command" value="Minimize"></OBJECT><button onClick="min.Click()">窗口最小化</button>
12、全屏代码
<input type="BUTTON" name="FullScreen" value="全屏显示"
onClick="window.open(document.location, ’butong_net’, ’fullscreen’)">
13、关闭窗口
<OBJECT id=closes type="application/x-oleobject"
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><param
name="Command" value="Close"></object><input type="button" value="关闭窗口" onClick="closes.Click();"> 关闭窗口
<input type=button value=关闭窗口
onClick="javascript:self.close()">
14、最大化 <object id=big
classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <param name="Command" value="Maximize"></object><input type=button value=最大化 onClick=big.Click()>
15、关闭输入法
<input style="ime-mode:disabled" value=关闭输入法> 16、链接按钮1
<input type="button" value="链接按钮1"
onClick="window.open(’http://www.winliuxq.com/’, ’Sample’, ’toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=790,height=520,left=0,top=0’)" name="input">
链接按钮2
<input type="BUTTON" NAME="Button" value="链接按钮2"
onClick="showModalDialog(’http://www.winliuxq.com/’)"> 链接按钮3
<input type="submit" value="链接按钮3"
onClick="location.href=’http://www.winliuxq.com/’"> 17、警告框显示源代码
<BUTTON onClick=alert(document.documentElement.outerHTML) style="width:110">警告框显示源代码</BUTTON>
18、点击后按钮清空
<input type=button value=’打印’
onClick="this.style.visibility=’hidden’;window.print();"> 19、打印
<input type=button value=’打印’ onClick="window.print();"> 20、打印预览
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button value=打印预览 onclick="wb.execwb(7,1)"> 21、另存为
<input onClick="document.execCommand(’saveas’,’true’,’常用代码.htm’)" type=button value=另存为>
22、点击自动复制 <script>function
oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}</script>
<input type="text" value="点击自动复制" onClick="oCopy(this)" size="11">
23、自动选中
<input value="自动选中" onFocus="this.select()" onMouseOver="this.focus()" size="11">
24、打开源代码
<BUTTON onClick="document.location = ’view-source:’ + document.location" size="7">打开源代码</BUTTON>
25、新窗口延迟打开
<input type=button value=新窗口延迟打开
onClick=javascript:setTimeout("window.open(’http://www.winliuxq.com/’)",10000)>
26、实现选中文本框里的前一半的内容
<input type="text" value="选中文本框里的前一半的内容" size=30
onmouseover="this.select();tR=document.selection.createRange();tR.moveEnd(’character’,-8);tR.select();">
<input type="text" value="选中部分内容,非IE可以用这个" size=30 onmouseover="this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length">
27、点击清空文字
<input type="text" name="artist" size=14 value="点击清空文字" onmouseover=this.focus() onfocus=this.select()
onclick="if(this.value==’点击清空文字’)this.value=’’"> 点击清空文字
<input name=name size=11 value=点击清空文字 onMouseOver=this.focus() onblur="if (this.value ==’’) this.value=’点击清空文字’"
onFocus=this.select() onClick="if (this.value==’点击清空文字’) this.value=’’">
28、等于标题(title):
<input type="text" value="" id="aa" size="20">
<script>document.getElementById("aa").value=document.title;</script>
29、检测IE是否脱机
<input type="button" value="测试"
onclick="alert(window.navigator.onLine)">
30、11种刷新按钮的方法
<input type=button value=刷新 onClick="history.go(0)"> <input type=button value=刷新 onClick="location.reload()"> <input type=button value=刷新 onClick="location=location"> <input type=button value=刷新
onClick="location.assign(location)"> <input type=button value=刷新
onClick="document.execCommand(’Refresh’)">
<input type=button value=刷新
onClick="window.navigate(location)"> <input type=button value=刷新
onClick="location.replace(location)">
<input type=button value=刷新 onClick="window.open(’自身的文件’,’_self’)">
<input type=button value=刷新
onClick=document.all.WebBrowser.ExecWB(22,1)>
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<form action="自身的文件"><input type=submit value=刷新></form> <a id=a1 href="自身的文件"></a><input type=button value=刷新 onClick="a1.click()">
31、
<a href="#" onClick=document.execCommand("open")>打开</a>
32、 <a
onclick="window.open(’i001.htm’,’’,’height=300,width=300,resizable=no,location=net’);" href="">打开指定大小网页</a>
33、
<a href="#" onClick=location.replace("view-source:"+location)>使用 记事本 编辑</a>
34、
<a href="#" onClick=document.execCommand("saveAs")>另存为</a> 35、
<a href="#" onClick=document.execCommand("print")>打印</a> <a href="javascript:window.print();">打印</a> 36、
<a href=mailto:429752806@163.com>发送E-mail</a>
37、
<a href="#" onClick=document.execCommand("selectAll")>全选</a> 38、
<a href="#" onClick=location.reload()>刷新1</a> 39、
<a href="#" onClick=history.go(0)>刷新2</a>
50、
<a href="i003.htm" onclick="return false;"
ondblclick="window.open(’i003.htm’);">双击打开链接</a>
51、
<style>#close a:hover
{background:url(javascript:window.opener=0;window.close());}</style><div id=close><a href="">关闭窗口</a></div>
52、
<A HREF="javascript:void(0)" onMouseover="alert(’对不起,禁止选中!’)">链接禁止</A>
53、滚动条在左侧,将<html>改为<HTML DIR="RTL"> 54、网页半透明
<body style="filter:Alpha(Opacity=50)">
55、随机选择背景色 <body> <script>
document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)]; </script>
56、框架页中不显示滚动条: <SCRIPT>
self.moveTo(0,0)
self.resizeTo(screen.availWidth,screen.availHeight) </SCRIPT>
57、防止网页被框架
<SCRIPT LANGUAGE=JAVASCRIPT>
if (top.location !== self.location) { top.location=self.location; } </SCRIPT>
58、永远都会带着框架
<script language="javascript"><!--
if (window == top)top.location.href = "frame.htm"; //frame.htm为框架网页
// --></script>
59、窗口自动最大化
<script language="JavaScript"><!-- self.moveTo(0,0)
self.resizeTo(screen.availWidth,screen.availHeight) //--></script>
60、打开窗口自动最大化
<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();"
VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT> 61、爽眼闪屏代码 <script>var color = new Array;color[1] = "black";color[2] = "white";for(x = 0; x <3; x++){document.bgColor = color[x];if(x == 2){x = 0;}}</script> 62、不能被另存为
<noscript><iframe src=*.html></iframe></noscript>
63、汉字字库调用 <script>
for(i=19968;i<40870;i++)document.write(String.fromCharCode(i)); </script>
64、显示现在时间的脚本
<script language=vbscript>document.write now</script> 65、显示最后修改时间的脚本
<script>document.write(document.lastModified)</script> 66、按下F12键,直接返回首页 <script>function look(){
if(event.keyCode==123){document.location.href=http://www.winliuxq.com/} }
if(document.onkeydown==null) {document.onkeydown=look} </script> 67、端口检测
<img src="http://www.winliuxq/zza.jpg" onload="alert(’端口可用’)" onerror="alert(’端口禁止’)"...> 68、无法最小化的窗口
<body onblur=’self.focus();’>
69、链接点外部css文件
<style>@import url("ie.css");</style>
70、内嵌式框架-网页中调用另外网页:
<object type="text/x-scriptlet" width="600" height="1000" data="http://www.dushuwu.net/"></object>
71、刷新改变窗口大小
<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();"
VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT> 72、JavaScript实现网页竖虚线
<script>hei=120;d1=2;d2=2;cou=Math.floor(hei/(d1+d2)); document.write(’<table cellspacing=0 cellpadding=0 width=1 height=’+hei+’>’);
for(i=0;i<cou;i++){document.write(’<tr><td height=’+d2+’><tr><td height=’+d1+’ bgcolor=333333>’)}</script></table>
73、js翻页
<script>document.write("<a
href="+location.href.replace(/\.html/g,"_2.html")+">2</a>");</script>
70种简单常用的JS代码的更多相关文章
- 127个常用的JS代码片段,每段代码花30秒就能看懂(上)
127个常用的JS代码片段,每段代码花30秒就能看懂(上) JavaScript 是目前最流行的编程语言之一,正如大多数人所说:“如果你想学一门编程语言,请学JavaScript.” FreeCode ...
- 常用的js代码片段
1.单选框/手风琴 <script> $(document).ready(function(){ $("dd").on("click",functi ...
- 几种自己主动运行js代码的方式
近期在看jquery,发现他竟然能自己主动运行js代码,于是就查了下.收集了几种经常使用的实现方法 jquery的方法 使用场景:不论什么须要运行的js特效 $(document).ready(fun ...
- 汇总前端最最常用的JS代码片段
html5选择器 //参数均接收一个合法的css选择器 element = document.querySelector('.foo,.bar');//返回带有foo或者bar样式类的首个元素 ele ...
- 汇总前端最最常用的JS代码片段-你值得收藏
原始出处,可拷贝:http://www.w3cfuns.com/notes/25068/1d0d350a974d879e63f1115cf80a3288.html 摘自:http://www.love ...
- 九款常用的JS代码高亮工具
代码高亮很重要,特别是当我们想要在网站或博客中展示我们的代码的时候.通过在网站或博客中启用代码高亮,读者更方便的读取代码块. 有很多免费而且有用的代码高亮脚本.这些脚本大部分由Javascripts编 ...
- 常用的js代码
1.输入框输入提示代码 <input name="keyword" type="text" value="请输入关键字" onFocu ...
- 网站建设中常用的JS代码段落
1.屏蔽左右键 这个不介绍了. <script language="JavaScript"> document.oncontextmenu=new Function(& ...
- 常用的JS代码块收集
/**数组去重一*/ (function (arr) { arr = arr.sort(); for (var i = 0; arr[i]; i++) { if (arr[i] === arr[i + ...
随机推荐
- 基于Select模型通信程序的编写,编译和执行
任务目标 编写Win32程序模拟实现基于Select模型的两台计算机之间的通信,要求编程实现服务器端与客户端之间双向数据传递.客户端向服务器端发送"计算从1到100的奇数和",服务 ...
- 分享spring、spring boot、spring cloud一些学习资源,从基础知识到项目实战
1.spring注解驱动开发,学习spring boot和spring cloud必备知识 链接: https://pan.baidu.com/s/1xhULzLlpkERhoMi1G5Lgfg 密码 ...
- C#简单的文件阅读器
写一个简单的文件阅读器 1.可以读取大文件(2G)2.实现首页.下一页.前一页.末页的跳转3.实现到指定页面的跳转,比如跳转到第**页4.限制每页显示字符数 1029-4069byte,且用户可自定 ...
- 希尔排序算法Java实现
希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...
- 开放定址法——线性探测(Linear Probing)
之前我们所采用的那种方法,也被称之为封闭定址法.每个桶单元里存的都是那些与这个桶地址比如K相冲突的词条.也就是说每个词条应该属于哪个桶所对应的列表,都是在事先已经注定的.经过一个确定的哈希函数,这些绿 ...
- Diycode开源项目 如何解决InputMethodManager造成的内存泄漏问题
1.内存泄漏的状况及原因 1.1.利用LeakCanary查看内存泄漏的状况 1.2.内存泄漏怎么产生的呢? InputMethodManager.mServicedView持有一个最后聚焦View的 ...
- PHP.35-TP框架商城应用实例-后台11-商品分类-删除分类(2种方法)、添加、修改
删除分类 删除一个分类的同时,其所有子分类都删除 在控制器CategoryCtroller.class.php中添加删除函数(delete) 在分类模型中添加钩子函数_before_delete()[ ...
- BZOJ 3027: [Ceoi2004]Sweet
容斥 #include<cstdio> using namespace std; int a,b,n,m[15]; long long ans=0,mod=2004; long long ...
- CC3200模块的内存地址划分和bootloader,启动流程(二)
1. 首先启动内部ROM固化的BOOT,然后这个ROM启动需要使用内存空间0X2000 0000 --- 0X2000 4000共16K的空间.一级BOOT的作用是串口升级和驱动库. 2. 然后是二级 ...
- Java 基本数据类型总结一
Java基本数据类型总结一 基本类型,或者叫做内置类型,是JAVA中不同于类的特殊类型.它们是我们编程中使用最频繁的类型.java是一种强类型语言,第一次申明变量必须说明数据类型,第一次变量赋值称为变 ...