你的位置:| 首页网站建设JavaScript常用代码→文章正文  
文章导航


JavaScript常用代码

_______________________________________


分割线?
<hr noshade size=0 color=#C0C0C0>
________________________________________

控制横向和纵向滚动条的显隐?
<body style="overflow-y:hidden"> 去掉x轴
<body style="overflow-x:hidden"> 去掉y轴
<body scroll="no">不显
________________________________________

表格变色
<TD onmouseover="this.style.backgroundColor='#FFFFFF'" onmouseout="this.style.backgroundColor=''"
style="CURSOR: hand">
________________________________________

禁止复制,鼠标拖动选取
<body ondragstart=window.event.returnValue=false oncontextmenu=window.event.returnValue=false onselectstart=event.returnValue=false>
________________________________________

普通iframe页面
<iframe name="name" src="main.htm" width="450" height="287" scrolling="Auto" frameborder="0"></iframe>
________________________________________

iframe自适应高度
<iframe name="pindex" src="/blog/index.asp" frameborder=false scrolling="auto" width="100%" height="100%" frameborder=no onload="document.all['pindex'].style.height=pindex.document.body.scrollHeight" ></iframe>
________________________________________

IE地址栏前换成自己的图标&可以在收藏夹中显示出你的图标
<link rel="Shortcut Icon" href="favicon.ico">
<link rel="Bookmark" href="favicon.ico">
________________________________________

字号缩放
越来越多的人长时间的泡网,眼镜的普及率也越来越高,让文字大点,让更多的用户看的更清楚。
<script type="text/javascript">
function doZoom(size)
{document.getElementById('zoom').style.fontSize=size+'px';}
</script>
<span id="zoom">需要指定大小的文字</span>
<a href="javascript:doZoom(16)">大</a> <a href="javascript:doZoom(14)">中</a> <a href="javascript:doZoom(12)">小</a>
________________________________________

select挡住div的解决方法
在div里加入下面的代码,根据需要调整就可以了。
<iframe src="/blog/javascript:false" scrolling="no" frameborder="0" style="z-index:-1;position:absolute; top:5px; left:2px;width:168;height:100px;">
</iframe>
________________________________________

iframe(嵌入式帧)自适应高度
填写的嵌入地址一定要和本页面在同一个站点上,否则会提示“拒绝访问!”。对跨域引用有权限问题,请查阅其他资料。
<iframe name="guestbook" src="/blog/gbook/index.asp" scrolling=no width="100%" height="100%" frameborder=no onload="document.all['guestbook'].style.height=guestbook.document.body.scrollHeight"></iframe>
________________________________________

跳转菜单新窗口
<select name="select" onchange="window.open(this.options[this.selectedIndex].value)">
<option value="http://www.microsoft.com/ie"> Internet Explorer</option>
<option value="http://www.microsoft.com"> Microsoft Home</option>
<option value="http://msdn.microsoft.com"> Developer Network</option>
</select>
________________________________________

flash透明选项
<param name="wmode" value="transparent">
________________________________________

添加到收藏夹和设为首页
<a href=# onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.makewing.com/lanren/');">设为首页</a>
<a href="javascript:window.external.AddFavorite('http://www.makewing.com/lanren/','懒人图库')">收藏本站</a>
________________________________________

记录并显示网页的最后修改时间
<script language=JavaScript>
document.write("最后更新时间: " + document.lastModified + "")
</script>
________________________________________

节日倒计时
<Script Language="JavaScript">
   var timedate= new Date("October 1,2002");
   var times= "国庆节";
   var now = new Date();
   var date = timedate.getTime() - now.getTime();
   var time = Math.floor(date / (1000 * 60 * 60 * 24));
   if (time >= 0)
   document.write( "现在离"+times+"还有: "+time +"天")
</Script>
________________________________________

加在HEAD里
禁止缓存
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
________________________________________

让IFRAME框架内的文档的背景透明
<iframe src="about:<body style='background:transparent'>" allowtransparency></iframe>
________________________________________

打开窗口即最大化
<script language="JavaScript">
<!-- Begin
self.moveTo(0,0)
self.resizeTo(screen.availWidth,screen.availHeight)
// End -->
</script>
________________________________________

加入背景音乐
<bgsound src="mid/windblue[1].mid" loop="-1"> 只适用于IE
<embed src="music.mid" autostart="true" loop="true" hidden="true"> 对Netscape ,IE 都适用
________________________________________

滚动
<marquee direction=up height=146 onmouseout=start() onmouseover=stop() scrollAmount=2>滚动信息
</marquee>
________________________________________

防止点击空链接时,页面往往重置到页首端
代码“javascript:void(null)”代替原来的“#”标记
________________________________________

文字或图片弹出指定大小的窗口
在body中加入
<script language="JavaScript" type="text/JavaScript">
function MM_openBrWindow(theURL,winName,features) {window.open(theURL,winName,features);}
</script>
弹出代码
<a href="#" target="_self" onClick="MM_openBrWindow('windows01.htm','','width=550,height=380')" width="550" height="380" border="0">图片或文字</a>
________________________________________

flash按钮加链接
on (press) {
getURL("http://www.makewing.com","_blank");
}
________________________________________

跳转页面代码
<meta http-equiv="refresh" content="5;url=http://www.makewing.com">
________________________________________

细线分隔线
<hr noshade size=0 color=#C0C0C0>
________________________________________

网页中的自动换行
<td style="word-break:break-all">就搞定了。
完整的是
style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word"
________________________________________

js 实现全选

<input type="checkbox" onclick="fun()">全选<br> 选中<input type="checkbox" id='1' name="c"><br> 选中<input type="checkbox" id='2' name="c"><br> 选中<input type="checkbox" id='3' name="c"><br> 选中<input type="checkbox" id='4' name="c"><br> 选中<input type="checkbox" id='5' name="c"><br> 选中<input type="checkbox" id='6' name="c"><br> </html> <script type="text/javascript"> function fun(){ var cs=document.getElementsByName("c"); for(i=0;i<cs.length;i++){ if(cs[i].checked) { cs[i].checked=false; }else{ cs[i].checked=true; } } } </script>
文章出处:DIY部落(http://www.diybl.com/course/1_web/javascript/Javascriptxl/20081022/150976.html)

 

控制checkbos
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function checkAll() {
for (var j = 1; j <= 9; j++) {
box = eval("document.checkboxform.C" + j);
if (box.checked == false) box.checked = true;
}
}

function uncheckAll() {
for (var j = 1; j <= 9; j++) {
box = eval("document.checkboxform.C" + j);
if (box.checked == true) box.checked = false;
}
}

function switchAll() {
for (var j = 1; j <= 9; j++) {
box = eval("document.checkboxform.C" + j);
box.checked = !box.checked;
}
}
// End -->
</script>
<form name=checkboxform>
<input type=checkbox name=C1 checked>C1<br>
<input type=checkbox name=C2 checked>C2<br>
<input type=checkbox name=C3 checked>C3<br>
<input type=checkbox name=C4 checked>C4<br>
<input type=checkbox name=C5 checked>C5<br>
<input type=checkbox name=C6 checked>C6<br>
<input type=checkbox name=C7 checked>C7<br>
<input type=checkbox name=C8 checked>C8<br>
<input type=checkbox name=C9 unchecked>C9<br>
<br>
<input type=button value="全部选中" onClick="checkAll()"><br>
<input type=button value="全部不选" onClick="uncheckAll()"><br>
<input type=button value="选择转换" onClick="switchAll()"><br>
</form>

文章出处:DIY部落(http://www.diybl.com/course/1_web/javascript/Javascriptxl/20081216/153978.html)

 

  上一页 1 2 3 4 5 下一页
 
公司简介 在线客服 客服中心 意见反馈 相关法律 隐私条款 广告服务 友情链接
Q链:515347638  电子邮箱:hanen@126.com 粤ICP备05086553