常用的JavaScript代碼

來源:互聯網
上載者:User
(1).在開啟的子視窗重新整理父視窗的代碼裡如何寫?
window.opener.location.reload()
(2).如何設定開啟頁面的大小
<body onload="top.resizeTo(300,200);">
開啟頁面的位置<body onload="top.moveBy(300,200);">
(3).在頁面中如何加入不是滿鋪的背景圖片,拉動頁面時背景圖不動
<STYLE>
body
{
background-image:url(/logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed
}
</STYLE>
(4). 檢查一段字串是否全由數字組成
<script language="Javascript">
function checkNum(str)
{
return str.match(//D/)==null
}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
</script>
(5). 獲得一個視窗的大小
document.body.clientWidth;
document.body.clientHeight
(6). 怎麼判斷是否是字元
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字元");
(7).TEXTAREA自適應文字行數的多少
<textarea rows=1 name=s1 cols=27 onpropertychange
="this.style.posHeight=this.scrollHeight">
</textarea>
(7).指令碼永不出錯
<SCRIPT LANGUAGE="JavaScript">
function killErrors()
{
return true;
}
window.onerror = killErrors;
</SCRIPT>
(8).ENTER鍵可以讓游標移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
(9).頁面進入和退出的特效
進入頁面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
推出頁面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">
這個是頁面被載入和調出時的一些特效。duration表示特效的期間,以秒為單位。transition表示使用哪種特效,取值為1-23:
0.矩形縮小 1.矩形擴大 2.圓形縮小 3.圓形擴大 4.下到上重新整理 5.上到下重新整理 6.左到右重新整理 7.右到左重新整理 8.豎百葉窗
9.橫百葉窗 10.錯位橫百葉窗 11.錯位豎百葉窗 12.點擴散 13.左右到中間重新整理 14.中間到左右重新整理 15.中間到上下
16.上下到中間 17.右下到左上 18.右上到左下 19.左上到右下 20.左下到右上 21.橫條 22.豎條 以上22種隨機播放一種
(10)、JavaScript首頁快顯視窗技巧
視窗中間彈出
<script>
window.open("http://www.cctv.com","","width=400,height=240,top="+(screen.availHeight-240)/2+",left="+(screen.availWidth-400)/2);
</script>
<html>
<head>
<script language="LiveScript">
function WinOpen() {
    msg=open("","DisplayWindow","toolbar=no,directories=no,menubar=no");
    msg.***("<HEAD><TITLE>哈 羅!</TITLE></HEAD>");
    msg.***("<CENTER><H1>酷 斃 了!</H1><h2>這 是<B>JavaScript</B>所 開 的 視 窗!</h2></CENTER>");
}
</script>
</head>
<body>
<form>
<input type="button" name="Button1" value="Push me" onclick="WinOpen()">
</form>
</body>
</html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.