用HTC实现自定义Html标签

HTML文件:
<html>
<head>
<script type="text/javascript">
function showCmd()
{
    alert(
"Ok");
}

</script>
<xml:namespace prefix="BNet">
<?IMPORT namespace="BNet" implementation="a.htc">
</head>
<body>
<BNet:Cmd onCmd="showCmd()">
命令内容
</BNet:Cmd>
</body>
</html>
HTC文件:
<public:component tagName="Cmd">

<public:event id = "rcCmdId" name="onCmd"/>
<public:attach event="onmouseover" onevent="mouseOver()" />
<public:attach event="onmouseout" onevent="mouseOut()" />
<public:attach event="onclick" onevent="doCmd()"/>
<public:attach event="ondocumentready" onevent="htcInit()" />
    
</public:component>
    
<script type="text/javascript">
function doCmd()
{
    
var oEvent = createEventObject();
    rcCmdId.fire(oEvent);
}


function htcInit()
{
    setAttribute(
"__htc_changed",new Object()); 
}


function set(prop,val)
{
    __htc_changed[prop] 
= eval(prop);
    eval(prop 
+ "='" + val + "'");    
}


function reset()
{
    
for(var prop in __htc_changed)
    
{
        eval(prop 
+ "='" + __htc_changed[prop] + "'");
    }

}



function mouseOver()
{
    set(
"style.color","#ff0000");
    set(
"style.cursor","hand");
}


function mouseOut()
{
    reset();
}

</script>
posted @ 2006-03-17 20:09  伊飏  阅读(560)  评论(0编辑  收藏  举报