`
q272156430
  • 浏览: 270193 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

css中behavior属性用法说明

    博客分类:
  • css
阅读更多

css中behavior属性用法说明:
我们经常会遇到在刷新表单的时候,表单中的内容就丢失了,我们常用的方法是使用cookie,但那样有点麻烦,在css中有behavior属性可以为我们解决这个问题。下面就介绍一下behavior这个属性的用法:
behavior的语法:
behavior : url ( url ) | url ( #objID ) | url ( #default#behaviorName )
取值:
url ( url ) : 使用绝对或相对 url 地址指定DHTML行为组件(.htc)
url ( #objID ) : 使用二进制实现(作为 ActiveX? 控件)的行为。此处的 #objID 为 object 对象的 id 属性值
url ( #default#behaviorName ) : IE的默认行为。由行为的名称标识( #behaviorName )指定
说明:设置或检索对象的DHTML行为。多个行为之间用空格隔开。
当多个附加到同一要素的行为发生冲突时,其结果取决于行为应用于要素的顺序。后一个行为的优先权高于前一个行为。同样的规则适用于不同行为提供的属性、事件、方法所发生的名称冲突。
可以使用 addBehavior 方法动态的将行为附着到对象。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
务必注意使用样式表(CSS)的 behavior 属性内联定义或使用 addBehavior 方法附着的行为不会在对象从文档树中移除时被自动分离。而在文档中的样式表规则定义的行为会在对象从文档树中移除时被自动分离。
对应的脚本特性为 behavior 。
实例:
p { behavior: url(#default#download); }
div { behavior: url(fly.htc) url(shy.htc); }
div { behavior: url(#myObject); }
应用1:刷新也保留输入框里面的文字
.sHistory {}{behavior:url(#default#savehistory);}
应用2:调用脚本
<html>
<head>
<style>
   h1 { behavior: url(behave.htc) }
   </style>
</head>
<body>
    <h1>把鼠标放在这里 http://www.phpzixue.cn/</h1>
</body>
</html>
  behave.htc
<component>
<attach for="element" event="onmouseover" handler="hig_lite" />
<attach for="element" event="onmouseout" handler="low_lite" />
<script type="text/javascript">
function hig_lite()
{
   element.style.color=255
}
function low_lite()
{
   element.style.color=0
}
</script>
</component>  
注意:CSS 时尽量避免使用Behaviors技术
Internet Explorer Behaviors
它是什么?Internet Explorer 5 引入了行为 (behaviors)。behaviors 是一种通过使用 CSS 向 HTML 元素添加行为的方法。
只有 Internet Explorer 支持 behavior 属性。
尽量使用 JavaScript 和 HTML DOM 代替它.

 

*.htc

 

<PUBLIC:COMPONENT ID="summerSelectObj" lightWeight="false" literalContent="true" NAME="summerSelectObj" supportsEditMode="false">
<PUBLIC:DEFAULTS canHaveHTML="true" contentEditable="false" tabStop="true"/>
<PUBLIC:PROPERTY ID="propData" NAME="data" PUT="setData" GET="getData"/>
<PUBLIC:attach  event="ondetach" onevent="cleanup()" />
<PUBLIC:attach event="oncontentready" onevent="fnInit()"/>
<PUBLIC:attach event="onfocus" onevent="fnMrShow()"/>
<PUBLIC:attach event="onblur" onevent="fnBlur()"/>
<PUBLIC:attach event="onclick" onevent="fnMrShow()"/>
<PUBLIC:attach event="onkeydown" onevent="fnKeyDown()"/>
<PUBLIC:attach event="onchange" onevent="fnOnchange()"/>
<PUBLIC:method   name="setValue"/>
<PUBLIC:method   name="setData"/>
<PUBLIC:method   name="fnFind"/>
<PUBLIC:method   name="fnInit"/>
<PUBLIC:method   name="fnIsClick"/>
<PUBLIC:method   name="fnGetLstStr"/>
<PUBLIC:method   name="fnMySort0"/>
<PUBLIC:method   name="fnMySort"/>
<PUBLIC:method   name="fnMySort2"/>
<PUBLIC:method   name="fnSortShow"/>
<PUBLIC:method   name="fnShowPopWin"/>
<PUBLIC:method   name="fnPropertyChange"/>
<PUBLIC:method   name="fnKeyDown"/>
<PUBLIC:method   name="fnClick"/>
<PUBLIC:method   name="fnAddFilter"/>
<PUBLIC:method   name="fnGetDescAndHidObj"/>
<PUBLIC:method   name="fnGetValue"/>
<PUBLIC:method   name="fnInitXml"/>
<PUBLIC:method   name="fnAjaxCb"/>
<PUBLIC:method   name="setInputRegExp"/>
<PUBLIC:method   name="createXMLHttpRequest"/>
<PUBLIC:method   name="fnGetAjaxData"/>
<PUBLIC:attach event="onpropertychange" onevent="fnPropertyChange()"/>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics