This article and we will focus on the use of CSS in the behavior attribute syntax, in the CSS page layout, we encountered the refresh to retain the contents of the form when the habit of using cookies, but it is very troublesome to do so, The behavior in CSS is good for us to solve this problem.
CSS Property behavior Syntax
In the CSS page layout, we encountered the refresh to keep the contents of the form when the habit of using cookies, but that is very cumbersome to do, CSS behavior for us to solve the problem well. Today we will introduce the syntax of CSS property behavior.
Behavior property Syntax:
Examplesourcecode
- Behavior:url (URL) |url (#objID) |url (#default #behaviorname)
Value:
URL (URL): Specifies the DHTML behavior component (. htc) with an absolute or relative URL address
URL (#objID): The behavior of using a binary implementation (as a activex® control). The #objid here is the ID property value of the object.
URL (#default #behaviorname): The default behavior of IE. specified by the name Identification (#behaviorName) of the behavior
Description: Sets or retrieves the DHTML behavior of an object. Multiple behaviors are separated by a space.
When multiple behaviors that are attached to the same feature conflict, the result depends on the order in which the behavior is applied to the feature. The priority of the latter behavior is higher than the previous behavior. The same rules apply to the name conflicts that occur with properties, events, and methods that are provided by different behaviors.
You can use the Addbehavior method to dynamically attach a behavior to an object.
This property is read-only for Currentstyle objects. Readable and writable for other objects.
It is important to note that using the Behavior property of the style sheet (CSS) inline definition or the behavior attached using the Addbehavior method is not automatically detached when the object is removed from the document tree. The behavior defined by the style sheet rule in the document is automatically detached when the object is removed from the document tree.
The corresponding script attribute is behavior.
Example:
Examplesourcecode
- P{behavior:url (#default #download);}
- Div{behavior:url (FLY.HTC) URL (shy.htc);}
- Div{behavior:url (#myObject);}
App 1: Refresh also preserves text inside the input box
Examplesourcecode
- . Shistory{}{behavior:url (#default #savehistory);}
App 2: Invoke script
Examplesourcecode
- <html>
- <head>
- <style>
- H1{behavior:url (BEHAVE.HTC)}
- </style>
- </head>
- <body>
- <H1> put the mouse here 52css.com</H1>
- </body>
- </html>
- Behave.htc
- <component>
- <attachforattachfor= "element"event= "onmouseover"handler=" hig_lite"/>
- <attachforattachfor= "element"event= "onmouseout"handler=" low_lite"/>
- <scripttypescripttype="Text/javascript">
- Functionhig_lite ()
- {
- element.style.color=255
- }
- Functionlow_lite ()
- {
- element.style.color=0
- }
- </Script>
- </Component>
Note: Try to avoid using behaviors technology when CSS
Internetexplorerbehaviors
What is it? InternetExplorer5 introduced the behavior (behaviors). Behaviors is a way to add behavior to HTML elements by using CSS.
Why should you avoid it? Only InternetExplorer supports the Behavior property.
What's the substitute for? Please use JavaScript and htmldom instead. Source: Http://blog.sina.com.cn/hksqbi