常用js脚本代码.docx
《常用js脚本代码.docx》由会员分享,可在线阅读,更多相关《常用js脚本代码.docx(13页珍藏版)》请在冰豆网上搜索。
![常用js脚本代码.docx](https://file1.bdocx.com/fileroot1/2023-1/21/8a6ee76d-f657-4181-aed3-2e09d54199b6/8a6ee76d-f657-4181-aed3-2e09d54199b61.gif)
常用js脚本代码
网页常用js代码
1、js实现div自适应高度
代码如下:
--
window.onload=window.onresize=function(){
if(document.getElementById("mm2").clientHeightdocument.getElementById("mm2").style.height=document.getElementById("mm1").offsetHeight+"px";}else{
document.getElementById("mm1").style.height=document.getElementById("mm2").offsetHeight+"px";}}
-->
1、后退前进
(1);returntrue;”type=”button”value=”前进”/>
2、返回
3、查看源码
4、禁止查看源码
5、刷新按钮一
//[CDATA[
functionReloadButton(){location.href="i
001.htm";}
//]]>
刷新按钮二
(0)”type=”button”value=”刷新按钮二”/>
6、回首页按钮
//[CDATA[
functionHomeButton(){location.href=http:
//]]>
7、弹出警告框
//[CDATA[
functionAlertButton(){window.alert("要多多光临呀!
");}
//]]>
8、状态栏信息
//[CDATA[
functionStatusButton(){window.status="要多多光临呀!
";}
//]]>
9、背景色变换
//[CDATA[
functionBgButton(){
if(document.bgColor=='#00ff')
{document.bgColor='#fff';}
else{document.bgColor='#00ff';}}//]]>
10、打开新窗口
//[CDATA[
function
NewWindow(){window.open("c
01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
//]]>
11、窗口最小化
d27cdb6e-ae6d-11cf-96b8-00″width=”100″height=”100″
codebase=”http:
12、全屏代码
name=”FullScreen”type=”BUTTON”value=”全屏显示”/>
13、关闭窗口
d27cdb6e-ae6d-11cf-96b8-00″
width=”100″height=”100″
codebase=”http:
关闭窗口
self.close()”type=”button”value=”关闭窗口”/>
14、最大化
d27cdb6e-ae6d-11cf-96b8-00″width=”100″height=”100″
codebase=”http:
15、关闭输入法
disabled;”value=”关闭输入法”/>
16、链接按钮1
„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”
type=”button”value=”链接按钮1″/>
链接按钮2
链接按钮3
17、警告框显示源代码
110px;”onclick=”alert(document.documentElement.outerHTML)”>警告框显示源代码
18、点击后按钮清空
19、打印
20、打印预览
d27cdb6e-ae6d-11cf-96b8-00″width=”0″height=”0″
codebase=”http:
type=”application/x-shockwave-flash”width=”0″height=”0″
name=”wb”>
21、另存为
22、点击自动复制
//[CDATA[
functionoCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}//]]>
23、自动选中
24、打开源代码
‟+document.location”>打开源代码
25、新窗口延迟打开
onclick=”javascript:
setTimeout(window.open(„http:
26、实现选中文本框里的前一半的内容
onmouseover=”this.select();tR=document.selection.createRange();tR.moveEnd(„character‟,-8);tR.select();”size=”30″type=”text”value=”选中文本框里的前一半的内容”/>
onmouseover=”this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length”size=”30″type=”text”value=”选中部分内容,非IE可以用这个”/>
27、点击清空文字
点击清空文字
onmouseover=”this.focus()”name=”name”size=”11″value=”点击清空文字”/>
28、等于标题(title):
//[CDATA[
document.getElementById("aa").value=document.title;
//]]>
29、检测IE是否脱机
30、11种刷新按钮的方法
(0)”type=”button”value=”刷新”/>
d27cdb6e-ae6d-11cf-96b8-00″width=”0″height=”0″
codebase=”http:
1.click()”type=”button”value=”刷新”/>
31、
打开
32、
onclick=”window.open(„i
33、
+location)”href=”#”>使用记事本编辑
34、
另存为
35、
打印window.print();”>打印
36、
6@
37、
全选
38、
刷新1
39、
(0)”href=”#”>刷新2
40、
+location)”href=”#”>查看源文件
41、
全屏显示
onclick=”window.open(document.location,url,fullscreen)”href=”#”>
42、
43、
单击右键将在新窗口中打开
44、
(1)”href=”#”>前进1
前进2
后退1
后退2
45、
整理收藏夹
hand;”title=”网页特效站点”
onclick=”window.external.addFavorite(„http:
{window.external.addFavorite(„http:
{window.sidebar.addPanel(„XX‟,'http:
{window.external.addFavorite(„http:
{window.sidebar.addPanel(„XX‟,'http:
{window.external.addFavorite(„http:
{window.sidebar.addPanel(„XX‟,'http:
onmouseover=”this.style.behavior=‟url(#default#homepage)‟;this.setHomePage(„http:
46、
window.close()”>关闭窗口
关闭窗口
3秒关闭本窗口//[CDATA[
functionshutwin(){
window.close();
return;}
//]]>
shutwin();”>关闭本窗口
47、hand;”onclick=”var
strHref=window.location.href;this.style.behavior=‟url(#default#homepage)‟;this.setHomePage(„http:
48、等于标题栏:
//[CDATA[
document.write(document.title);
//]]>
49、
href=”javascript:
void
(0);”>收藏本页
window.external.AddFavorite(document.location.href,document.title)”>收藏本页
window.external.addChannel(“>加入频道
window.external.addChannel(“>
50、
003.htm‟);”href=”i
003.htm”>双击打开链接
51、
–#closea:
url(javascript:
window.opener=0;window.close());}–>关闭窗口