JavaScript指令碼集合

來源:互聯網
上載者:User

 

如何讓iframe根據內容適應高度

<iframe src="http://www.baidu.com" onload="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 oncontextmenu=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=最小化 onclick=hh1.Click()>
<input type=button value=最大化 onclick=hh2.Click()>
<input type=button value=關閉 onclick=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>

關閉IME

<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.onkeydown=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 onblur="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:expression(document.body.clientWidth/2-10);top:expression(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" />

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.