Javascript代碼在網頁中簡單應用的幾個樣本

來源:互聯網
上載者:User

在表格裡本來居左的圖片當點擊(圖片或表元)後移到表格的置中位置:

以下為引用的內容:
<script language="JavaScript">
function call(xxx){
xxx.align="left";
}
function letback(yyy){
yyy.align="right";
}
</script>


檔案裡面這樣引用:

以下為引用的內容:
<td id="mainbtn3" align="right" height="31" onClick="MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','show')" width="250"><img src="images/redbtn_3.gif" width="216" height="21" onClick="letback(mainbtn1);letback(mainbtn2);call(mainbtn3)" style="cursor:w-resize"></td>  

 
xp樣式菜單效果

以下為引用的內容:
<script language="JavaScript" type="text/javascript">
<!--
function rollon(a) {
a.style.backgroundColor='#C8C8C8';
a.style.border = '#808080 solid 1px'; } function rolloff(a) {
a.style.backgroundColor='#E4E4E4';
a.style.border = '#E4E4E4 solid 1px';
}
//-->
</script>
<style type="text/css">
<!--
.off { background-color: #e4e4e4; border-color: #e4e4e4 #E4E4E4 #E4E4E4; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</style>


HTML連結處用:

以下為引用的內容:
<tr>
<td class="off" onMouseOut="rolloff(this);" onMouseOver="rollon(this);" height="12"><a href="#">
Summary Report</a> </td>
</tr>

 

極酷的跟隨滑鼠的帶年月日顯示的動態時鐘CLOCK 
 
一個連結改變多個目標幀檔案的內容

以下為引用的內容:
<script language="javascript">
function frame_loader(targetLeft,targetMain){
parent.leftFrame.location.href= targetLeft;
parent.mainFrame.location.href= targetMain;
}
</script>
<a
href="javascript:frame_loader('default_left.asp','default_body.asp')">Link</a>

 
左右擊都在本頁開啟目標頁

以下為引用的內容:

<script language="JavaScript">
<!--
function clicklink() {window.location="index.html"}
//-->
</script>

IN HTML:

 

<body bgcolor="#FFFFFF" text="#000000" onMouseDown="clicklink()"> 
 

 
檢測螢幕解析度匯入不同頁面


以下為引用的內容:
<script language="JavaScript">
<!--
function KBScreenGoToURL(Big,Medium,Small,Tiny) {
// Copyright (c) 1998 by Kevin Bartz. All rights reserved. This site has been enhanced by one of Kevin Bartz's behaviours! Mail him at kevinbartz@geocities.com! This line must remain in the script.
IE4=(document.all) ? 1:0
NS4=(document.layers) ? 1:0
if (NS4 | IE4) {
var h=screen.height
var w=screen.width
if (h<580 & w<740) {
window.location=Tiny
} else if (h<674 & w<835) {
window.location=Small

} else if (h<768 & w<929) {
window.location=Medium
} else {
window.location=Big
}
}
}
//-->
</script>

 


HTML:


以下為引用的內容:
<p>
<body bgcolor="#FFFFFF" onLoad="KBScreenGoToURL('1024.htm','1024.htm','800.htm','800.htm')">

 

或者用下面這段:

以下為引用的內容:
<html>
<head>
<script language=javascript>
<!--
function mHref() {
if (screen.width == 1024) location.href = "htm2.htm";
else if (screen.width == 800) location.href = "htm1.htm";
else return(false);
}
//-->
</script>
</head>
<body onload="mHref();">
</body>
</html>

 
點擊一個連結開啟二個不同頁面的視窗
<A href="http://msdn.microsoft.com/vs/techinfo/" target="_blank" onClick="window.open('temp.htm','','')">Visual Studio</A>

 

這二個頁面都將在新視窗中開啟,如果要在本頁開啟,不能用windo.open要用:window.location=""或document.location.href=""


隱藏目的地區域的下拉框等組件

隱藏目的地區域的下拉框等組件,讓它在層(菜單)出現時不擋住目標層(抄自微軟)


代碼如下:

以下為引用的內容:

<script language="JavaScript" type="text/javascript">
<!--
function hideElement(elmID)
{
for (i = 0; i < document.all.tags(elmID).length; i++)
{
obj = document.all.tags(elmID)[i];
if (! obj || ! obj.offsetParent)
continue;
// Find the element's offsetTop and offsetLeft relative to the BODY tag.
objLeft = obj.offsetLeft;
objTop = obj.offsetTop;
objParent = obj.offsetParent;
while (objParent.tagName.toUpperCase() != "BODY")
{
objLeft += objParent.offsetLeft;
objTop += objParent.offsetTop;
objParent = objParent.offsetParent;
}
if (objTop < 250){
obj.style.visibility = "hidden";
}
}
}
function showElement(elmID)
{
for (i = 0; i < document.all.tags(elmID).length; i++)
{
obj = document.all.tags(elmID)[i];
if (! obj || ! obj.offsetParent)
continue;
obj.style.visibility = "";
}
}
function hidelayer()
{var i; for(i=1;i<=4;++i){document.all['nav'+i].style.visibility='hidden';}
showElement("SELECT");
showElement("OBJECT");
showElement("IFRAME");}
function showlayer(index)
{document.all['nav'+index].style.visibility='visible';
hideElement("SELECT");
hideElement("OBJECT");
hideElement("IFRAME");}
//-->
</script>
 

 

聯繫我們

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