当前位置: 首页 > 图文教程 > 网络编程 > Javascript > Javascript代码在网页中简单应用的几个示例

Javascript
jQuery生成asp.net服务器控件的代码
javascript 实现的完全兼容鼠标滚轴缩放图片的代码
JavaScript学习笔记(十七)js 优化
使用SyntaxHighlighter实现HTML高亮显示代码的方法
javascript contains和compareDocumentPosition 方法来确定是否HTML节点间的关系
利用jQuery 实现GridView异步排序、分页的代码
jquery.lazyload 实现图片延迟加载jquery插件
Lazy Load 延迟加载图片的 jQuery 插件
jquery 插件实现图片延迟加载效果代码
javascript小数计算出现近似值的解决办法
jquery1.4后 jqDrag 拖动 不可用
jquery 应用代码 方便的排序功能
选择TreeView控件的树状数据节点的JS方法(jquery)
jquery 图片Silhouette Fadeins渐显效果
JQuery Dialog(JS 模态窗口,可拖拽的DIV)
javascript 同时在IE和FireFox获取KeyCode的代码
js 键盘记录实现(兼容FireFox和IE)
javascript 函数速查表
jQuery AnythingSlider滑动效果插件
经典海量jQuery插件 大家可以收藏一下

Javascript代码在网页中简单应用的几个示例


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 86 ::
收藏到网摘: n/a

在表格里本来居左的图片当点击(图片或表元)后移到表格的居中位置:

以下为引用的内容:
<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 [email protected]! 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>