收藏些常用JavaScript代碼

來源:互聯網
上載者:User

點擊返回上頁代碼:
<form>
<p><input TYPE="button" VALUE="返回上一步" ONCLICK="history.back(-1)"></p>
</form>

彈出警告框代碼:
<form>
<p><input TYPE="button" VALUE="彈出警告框" ONCLICK="AlertButton()"></p>
</form>
<script language="JavaScript"><!--
function AlertButton(){window.alert("要多多光臨呀!");}
// --></script>

點擊開啟新視窗
<form>
<p><input TYPE="button" VALUE="開啟新視窗" ONCLICK="NewWindow()"></p>
</form>
<script language="JavaScript"><!--
function NewWindow(){window.open("http://www.mcmx.com","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// --></script></body>

刪除記錄時彈出確認框:
<script LANGUAGE="VBSCRIPT">
a=msgbox("真的要刪除該記錄嗎?",1,"注意")
if a=1 then
location="Dodelete.asp?id=<%=id%>" //指向執行刪除的頁面Dodelete.asp
else
history.go(-1)
end if
</script>

關閉開啟的視窗
< a href="/" onclick="javascript:window.close(); return false;">關閉視窗</a>

清空INPUT且選定
onClick="Javascript:this.value=''" onFocus="this.select()" onMouseOver="this.focus()"

右鍵屏蔽
<body oncontextmenu=self.event.returnValue=false>

連串英文自動換行的解決方案 IE5.5
style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word" 你可修改為指定的大小如 200px

圖片“重設”按鈕
<script language="jscript">
function myreset()
{ document.login.reset();
document.login.focus();}
</script>
<img src="image/reclear.gif" width="69" height="20" style="cursor:hand" onfocus="this.blur()" onclick="myreset()"

畫細線表格
<table style="border-collapse: collapse">

狀態列資訊
<form>
<p><input TYPE="button" VALUE="狀態列資訊" ONCLICK="StatusButton()"></p>
</form>
<script language="JavaScript"><!--
function StatusButton(){window.status="要多多光臨呀!";}
// --></script>

最小化、最大化、關閉視窗
<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

隱藏狀態列裡出現的LINK資訊
<a href="http://"; onMouseOver="window.status='none';return true">夢想天空</a>

文字框自動捲軸
<textarea name=words rows=18 cols=26 style="border:1 solid #000000;background-color:white; font-size:9pt; width:188; overflow:auto" wrap=hard></textarea>

全選並複製
<FORM name=test><INPUT onclick="javascript:HighlightAll('test.select1')" type=button value=全選並複製><BR><TEXTAREA name=select1 rows=3 cols=46>你好,歡迎您的光臨!</TEXTAREA>
</FORM>
<SCRIPT language=Javascript>
<!--

var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</SCRIPT>

屏蔽JAVASCRIPT錯誤
<script language="JavaScript">
<!--
function killErrors(){
return true;
}
window.onerror = killErrors;
-->
</script>

關閉子視窗時重新整理父視窗
<script language="JavaScript">
<!--
self.opener.location.reload();
window.close()
-->
</script>

背景色變換
<form>
<p><input TYPE="button" VALUE="背景色變換" onClick="BgButton()"></p>
</form>
<script>function BgButton(){
if (document.bgColor=='#00ffff')
{document.bgColor='#ffffff';}
else{document.bgColor='#00ffff';}
}
</script>

檢查一段字串是否全由數字組成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

判斷是否是字元
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");

點擊重新整理代碼:
<form>
<p><input TYPE="button" VALUE="重新整理按鈕一" ONCLICK="ReloadButton()"></p>
</form>
<script language="JavaScript"><!--
function ReloadButton(){location.href="allbutton.htm";}
// --></script>

讓層不被控制項複蓋代碼:
<div z-Index:2><object xxx></object></div> # 前面
<div z-Index:1><object xxx></object></div> # 後面
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>

讓層的相對定位
<div id="Layer1" style="position:relative; left:0px; top:0px; width:0px; height:0px;z-index:1">
<div id="Layer2" style="position:absolute; left:500px; top:0px; width:220px; height:220px; z-index:1">
內容
</div></div>

Flash代碼以及背景透明
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="200" height="200">
<param name="movie" value="檔案">
<param name="quality" value="high">
<param name="wmode" value="transparent">
<embed src="images/fish.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="220" height="220"></embed></object>

Windows Media Player 播放器
<OBJECT id=MediaPlayer1
style="LEFT: 0px; VISIBILITY: visible; POSITION: absolute; TOP: 0px;z-index:2"
codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701standby=

Loading
type=application/x-oleobject height=300 width=320
classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 VIEWASTEXT>
<PARAM NAME="URL" VALUE="地址">

<param name="AudioStream" value="-1">
<param name="AutoSize" value="0">
<param name="AutoStart" value="-1">
<param name="AnimationAtStart" value="0">
<param name="AllowScan" value="-1">
<param name="AllowChangeDisplaySize" value="-1">
<param name="AutoRewind" value="0">
<param name="Balance" value="0">
<param name="BaseURL" value>
<param name="BufferingTime" value="5">
<param name="CaptioningID" value>
<param name="ClickToPlay" value="-1">
<param name="CursorType" value="0">
<param name="CurrentPosition" value="-1">
<param name="CurrentMarker" value="0">
<param name="DefaultFrame" value>
<param name="DisplayBackColor" value="0">
<param name="DisplayForeColor" value="16777215">
<param name="DisplayMode" value="0">
<param name="DisplaySize" value="4">
<param name="Enabled" value="-1">
<param name="EnableContextMenu" value="-1">
<param name="EnablePositionControls" value="0">
<param name="EnableFullScreenControls" value="0">
<param name="EnableTracker" value="-1">
<param name="InvokeURLs" value="-1">
<param name="Language" value="-1">
<param name="Mute" value="0">
<param name="PlayCount" value="1">
<param name="PreviewMode" value="0">
<param name="Rate" value="1">
<param name="SAMILang" value>
<param name="SAMIStyle" value>
<param name="SAMIFileName" value>
<param name="SelectionStart" value="-1">
<param name="SelectionEnd" value="-1">
<param name="SendOpenStateChangeEvents" value="-1">
<param name="SendWarningEvents" value="-1">
<param name="SendErrorEvents" value="-1">
<param name="SendKeyboardEvents" value="0">
<param name="SendMouseClickEvents" value="0">
<param name="SendMouseMoveEvents" value="0">
<param name="SendPlayStateChangeEvents" value="-1">
<param name="ShowCaptioning" value="0">
<param name="ShowControls" value="-1">
<param name="ShowAudioControls" value="-1">
<param name="ShowDisplay" value="0">
<param name="ShowGotoBar" value="0">
<param name="ShowPositionControls" value="-1">
<param name="ShowStatusBar" value="-1">
<param name="ShowTracker" value="-1">
<param name="TransparentAtStart" value="-1">
<param name="VideoBorderWidth" value="0">
<param name="VideoBorderColor" value="0">
<param name="VideoBorder3D" value="0">
<param name="Volume" value="70">
<param name="WindowlessVideo" value="0">
</OBJECT>

RealPlayer 播放器
<object id=video1 classid=" clasid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA"
width=320 height=240 align="middle">
<param name="controls" value="inagewindow">
<param name="console" value="chicp1">
<param name="autostar" value="true">
<param name="src" value="地址">
<embed
src="地址"
type="audio/x-pn-realaudio-plugin" console="chip1"
controls="imagewindow" width=320 height=240 autostart=true align="middle">
</embed>
</object>

 

相關文章

聯繫我們

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