JavaScript脚本集合

 

如何让iframe根据内容适应高度

<iframe src="http://www.baidu.com" οnlοad="this.height = this.document.body.offsetHeight;this.width=this.document.body.offsetWidth;"></iframe>

window.close()怎样使得关闭窗口时,ie不弹出确认对话框

<input type="button" onClick="window.opener='xxx';window.close();" value="IE6最简单的无提示关闭窗口" >

屏蔽右键菜单

非js方法:〈body οncοntextmenu=self.event.returnValue=false〉

js方法:

  if (window.Event)
    document.captureEvents(Event.MOUSEUP);
  
  function nocontextmenu()
  {
   event.cancelBubble = true
   event.returnValue = false;
  
   return false;
  }
  
  function norightclick(e)
  {
   if (window.Event)
   {
    if (e.which == 2 || e.which == 3)
     return false;
   }
   else
    if (event.button == 2 || event.button == 3)
    {
     event.cancelBubble = true
     event.returnValue = false;
     return false;
    }
  
  }
  
  document.oncontextmenu = nocontextmenu;  // for IE5+
  document.onmousedown = norightclick;  // for all others


判断分辨率

<script>
alert(screen.width+'*'+screen.height)
</script>

关闭窗口三种办法

方法一:window.close();
通常情况下:window.opener=null;window.close();都是可行的。
所述的情况下,window.close()失效
方法二:
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" VALUE="Close"></OBJECT>

<input type=button value=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=关闭 οnclick=hh3.Click()>
本例适用于IE
但在通常的网页中,结果是:“仅在HTML帮助中才有此功能”!

方法三:
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2
height=0 width=0></OBJECT>

window.document.all.WebBrowser.ExecWB(45,1);
所述的问题,但有限制,就是要降低IE的安全级别。

只能输入数字正则

<input onKeyUp="value=value.replace(//D+/g,'')">

只能输入中文正则

<input onKeyUp="value=value.replace(/[ -}]/g,'')">

用回车提交表单

<body onLoad="form.txt.focus()">
<form name="form">
<input name="txt" size="100" value="Mouse点我提交,按Enter也提交" onClick="form.submit()" onKeyDown="if (event.keyCode==13)form.submit()">
</form>

通过层来实现渐淡淡出

<script language="JavaScript1.2">
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=50
}
</script>
<div style="width:200px;height:200px;filter:alpha(opacity=50);border:1px solid #000;background:#0000FF" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)">
ywicc.com
</div>

关闭输入法

<input style="ime-mode:disabled">

永远都会带着框架

<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script>

防止被人frame

<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

网页将不能被另存为

<noscript><iframe src=*.html></iframe></noscript>

取得控件的绝对位置

//Javascript
<script language="Javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}

  屏蔽功能键Shift,Alt,Ctrl

<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift键!"); //可以换成ALT CTRL
}
document.οnkeydοwn=look;
</script>

网页不会被缓存

<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META HTTP-EQUIV="expires" CONTENT="0">


java 版

  // 设置编码方式及缓存;
  response.setContentType("text/html; charset=GB2312");
  response.setHeader("Pragma", "No-cache");
  response.setHeader("Cache-Control", "no-cache");
  response.setDateHeader("Expires", 0);

怎样让表单没有凹凸感

<input type=text style="border:1 solid #000000">

<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 1 solid #000000"></textarea>


<div><span>&<layer>的区别

<div>(division)用来定义大段的页面元素,会产生转行
<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
<layer>是ns的标记,ie不支持,相当于<div>

让弹出窗口总是在最上面

<body οnblur="this.focus();">

电子邮件处理提交表单

<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type=submit>
</form>

  限制下拉选择的宽度

<select name="select" style="width:300"></select>

弹出的窗口居中

一:

<script>
myWin=window.open("about:blank","","width=200,height=160");
myWin.moveTo(screen.width/2-100,screen.height/2-80);
</script>

二:

<script>
t = 200;
l = 200;
window.open('about:blank','','width='+l+',height='+t+',top='+(screen.availHeight/2-t/2)+',left='+(screen.availWidth/2-l/2));
</script>

showModalDialog 的内嵌弹出
<script>
window.showModalDialog("about:<script>window.open('','w_name','status=no');window.close()<//script>","","dialogwidth=0px;dialogheight=0px")  //用模式窗口做个过度就可以了
window.open("你要弹出的地址","w_name","")
</script>

有关title换行的问题

<a href="/" title="51js 无忧脚本 逍遥云">无忧脚本</a>

背景图片居中

<body style="background-image: url(http://www.yesky.com/image20010518/122306.gif); background-attachment: fixed; background-repeat: no-repeat;  background-position: center"></body>

<div style="position:absolute;left:e­xpression(document.body.clientWidth/2-10);top:e­xpression(document.body.clientHeight/2-10);">
<img src="http://bbs.51js.com/images/smilies/smile.gif">
</div>

引入样式表(css)的四种方式

一、使用STYLE属性: 将STYLE属性直接加在个别的元件标签里。
<元件(标签) STYLE="性质(属性)1: 设定值1; 性质(属性)2: 设定值2; ...}
例如:
<TD STYLE="COLOR:BLUE; font-size:9pt; font-family:"标楷体"; line-height:150%>
这种用法的优点 是可灵巧应用样式於各标签中,但是缺点则是没有整篇文件的『统一性』。

二、使用STYLE标签: 将样式规则写在<STYLE>...</STYLE>标签之中。
<STYLE TYPE="text/css">
<!--
样式规则表
-->
</STYLE>
例如:
<STYLE TYPE="text/css">
<!--
BODY {
  color: BLUE;
  background: #FFFFCC;
  font-size: 9pt}
TD, P {
  COLOR: GREEN;
  font-size: 9pt}
-->
</STYLE>
通常是将整个的 <STYLE>...</STYLE>结构写在网页的<HEAD> </HEAD>部份之中。这种用法的优点就是在於整篇文件的统一性,只要是有声明的的元件即会套用该样式规则。缺点就是在个别元件的灵活度不足。

三、使用 LINK标签: 将样式规则写在.css的样式档案中,再以<LINK>标签引入。
假设我们把样式规则存成一个example.css的档案,我们只要在网页中加入
<LINK REL=STYLESHEET TYPE="text/css" HREF="example.css">
即可套用该样式档案中所制定好的样式了。 通常是将LINK标签写在网页的<head></head>部份之中。这种用法的优点就是在於可以把要套用相同样式规则的数篇文件都指定到同一个样式档案即可。缺点也是在个别文件或元件的灵活度不足。


四、使用@import引入: 跟LINK用法很像,但必 放在<STYLE>...</STYLE> 中。
<STYLE TYPE="text/css">
<!--
  @import url(引入的样式表的位址、路径与档名);
-->
</STYLE>
例如:
<STYLE TYPE="text/css">
<!--
  @import url(http://yourweb/ example.css);
-->
</STYLE>

链接时候下陷效果

<style>
A:link,A:visited ,A:active {TEXT-DECORATION: none}
A:hover {text-decoration : none; position : relative; top : 1px; left : 1px}
</style>

<A HREF="http://be10.ods.org/51js/forumdisplay.php?fid=9">来来,都到这里来……</A>
<A HREF="http://winsky0.yeah.net">你把一个人看简单了,这个人就是winsky……*&^(*(*)</A>

将你的网页的图标改掉,注意ico文件大小为:16*16

<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

为搜索引擎准备的内容

允许搜索机器人搜索站内所有链接。如果你想某些页面不被搜索,推荐采用robots.txt方法
<meta content="all" name="robots" />
设置站点作者信息
<meta name="author" content="ajie@netease.com,阿捷" />
设置站点版权信息
<meta name="Copyright" content="www.w3cn.org,自由版权,任意转载" />
站点的简要介绍(推荐)
<meta name="description" content="新网页设计师。web标准的教程站点,推动web标准在中国的应用" />
站点的关键词(推荐)
<meta content="designing, with, web, standards, xhtml, css, graphic, design, layout, usability,

ccessibility,w3c, w3, w3cn, ajie" name="keywords" />

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UniMagic

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值