How to use HTC (GO)

Source: Internet
Author: User

One. Two ways to use HTC:
    1. Association behavior (Attach Behavior): IE 5.0 above support , HTC Technology appeared in the original intention. The main goal is to wrap the object's complex style changes in lieu of JavaScript + CSS.
    2. Elemental behavior (Element Behavior): more than IE 5.5 support , advanced application of HTC Technology. The main purpose is to use HTC to create custom tags in HTML files (equivalent to custom tags in JSP technology).

Two. Example of association behavior (tested in Windows Xp, IE6.0)

    1. Write an. htc file. (STYLE.HTC)

<public:attach event= "onmouseover" onevent= "F_mouse_over ()"/>

<public:attach event= "onmouseout" onevent= "f_mouse_out ()"/>

<public:attach event= "onclick" onevent= "F_click ()"/>

<public:method name= "Makedisplay ()"/>

<public:method name= "Makeundisplay ()"/>

<script>

function F_mouse_over () {//Make font red, position shifted right 5px

Element.style.color= "Red";

element.style.posleft+=5;

}

function F_mouse_out () {//Make font blue, position shifted left 5px

Element.style.color= "Blue";

element.style.posleft-=5;

}

function F_click () {//Click on the mouse to turn into a glow display, can be Onmousedown,onmouseup event refinement processing

Element.style.color= "Red";

Element.style.filter= "Glow (color=red,strength=2)";

}

function Makedisplay () {//Make the object visible

element.style.display= "Block";

}

function Makeundisplay () {//Make the object invisible

Element.style.display= "None";

}

</script>

2. Writing HTML files (test.html)

<style>

. teststyle{

Behavior:url (STYLE.HTC);

}

</style>

<body>

<div style= "width:200px;height:200px" class= "Teststyle" id= "Testdiv" >test Text; Please move mouse on this area!</div><br/>

<button onclick= "Testdiv.makedisplay ();" Name= "Display"/><button onclick= "Testdiv.makeundisplay ();" Name= "No display"/>

</body>

3. Description: In theory, HTC file can be used to modify the style of the object classname, using the HTML style, HTC inside with style defined styles can not be used. However, if you modify the classname, the object will no longer be associated with this HTC style , and this HTC style has no effect on the object.

Three. Example of element behavior (windowsxp, IE6.0 on test)

    1. Writing an. htc file (ELEMENT.HTC)

<public:component tagname= "LoginForm" >

<public:property name= "UserName" value= "username"/>

<public:property name= "password" value= "password"/>

<public:property name= "Action"/>

<public:property name= "Firststyle"/> <!--user name input box style--

<public:property name= "Secondstyle"/>

<public:attach event= "Oncontentready" onevent= "init ()"/>

<public:method name= "Close"/>

<public:defaults tabstop=true contenteditable=false canhavehtml=true viewinheritstyle=false viewMasterTab=false/ >

</public:component>

<style>

. name{
background-color:red;
}
. pass{
Background-color:blue;
}

</style>

<script>
var_table;

function init () {

if (typeof (action) = = "Undefined" | | action==null) {

Alert ("Action property is missing!");

Return

The}//action property must
Var_form=document.createelement ("<form></form>");
_form.action=action;

_table=document.createelement ("<table></table>");
var otr1=_table.insertrow ();
var Otd1=otr1.insertcell ();
Otd1.innertext=username+ ":";
var Otd2=otr1.insertcell ();
var _username=document.createelement ("<inputtype=text></input>");
if (typeof (Firststyle)! = "undefined" &&firststyle!=null) {
_username.classname=firststyle;
}
Otd2.appendchild (_username);
var otr2=_table.insertrow ();
var Otd3=otr2.insertcell ();
Otd3.innertext=password+ ":";
var Otd4=otr2.insertcell ();
var _password=document.createelement ("<inputtype=password></input>");
if (typeof (Secondstyle)! = "undefined" &&secondstyle!=null) {
_password.classname=secondstyle;
}
Otd4.appendchild (_password);
Otr3=_table.insertrow ();
Otd5=otr3.insertcell ();
var _okbtn=document.createelement ("<inputtype=submit></input>");
Otd5.appendchild (_OKBTN);
Otd6=otr3.insertcell ();
var _resetbtn=document.createelement ("<inputtype=reset></input>");
Otd6.appendchild (_RESETBTN);

_form.appendchild (_table);

Document.body.appendChild (_form);

Defaults.viewlink=document;

}

function Close () {//delete itself on call
var allele=document.body.childnodes;
for (Var i=0;i<allele.length;i++) {
Document.body.removeChild (Allele[i]);
}
}

</script>

<body></body>

Two. Writing the. html file (test.html)

<?xml:namespace prefix= "Custom"/>
<? IMPORT namespace= "Custom" implementation= "ELEMENT.HTC"/>

<style>
. name{
color:red;
}
. pass{
Color:blue;
}
</style>
<body>
<custom:loginform action= "/login.do" id= "AAA" firststyle= "name" secondstyle= "Pass" ></custom:loginForm> <br/>
<input type= "button" onclick= "Aaa.close ();" value= "Delete Login box"/>
</body>

3. Description: The elements generated by JavaScript in HTC can be added to the custom control (with Document.body.appendChild ()) or directly to the main HTML file ( Use Window.document.body.appendChild ()). (the HTC file and the host HTML file share a Window object, so HTC can directly control the HTML file )

4.HTC official MSDN Documentation: HTC Reference

How to use HTC (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.