地重复书写HTML、CSS和javascript的代码,以满足多个页面上的重复或相似的功能。自IE 5.0浏览器发布后,这种情况得到了改善,它带给我们一个新的指令组合方法,可把实现特定功能的代码封装在一个组件内,从而实现多页面的代码重用,使网页编程进入一个
////////////////////////“行为”文档
开始////////////////////////////
//给“行为”增加四个鼠标事件
<P
ubLIC:ATTACH EVENT="onmouseover" ONEVENT="glow
IT()"/>
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()"/>
<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="font2yellow()"/>
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="font2blue()"/>
//给“行为”定义二个方法,注意N
amE的值里不能加括号
<PUBLIC:METHOD NAME="move_down"/>
<PUBLIC:METHOD NAME="move_right"/>
<script language ="JScript">
//定义一个保存
字体颜色的变量
VAR font_color;
//定义向下移动文字的方法
function 
;move_down()
{
element.style.posTop += 10;
}
//定义向右移动文字的方法
function move_right()
{
element.style.posLeft += 10;
}
//定义鼠标onmouseup事件的调用函数
function font2blue()
{
if (event.srcElement
== element)
{
element.style.color = "blue";
}
}
//定义鼠标onmousedown事件的调用函数
function font2yellow()
{
if (event.srcElement == element)
{
element.style.color = "yellow";
}
}
//定义鼠标onmouseover事件的调用函数
function glowit()
{
if (event.srcElement == element)
{
font_color=style.color;
element.style.color = "white";
element.style.filter = "glow(color=
red, strength=2)";
}
}
//定义鼠标onmouseout事件的调用函数
function noglow()
{
if (event.srcElement == element)
{
element.style.filter = "";
element.style.color = font_color;
}
}
</script>
//////////////////“行为”文档结束///////////////////////////////
<html>
<head>
<title>行为效果演示</title>
<style>
.myfilter{behavior:url(font_effect.htc);position:relative;width:880}
</style>
</head>
<body>
<button onclick="myspan.move_right();">向右移动文字</button>
<button onclick="myspan.move_down();">向下移动文字</button>
<
br /><br />
<span id="myspan" class='myfilter'>鼠标指向后产生辉光,同时文字变白;按下鼠标后文字变黄;抬起鼠标后文字变蓝;鼠标离开后文字恢复原状</span>
</body>
</html>