用HTC实现自定义Html标签

本文介绍了一个HTML文件如何通过HTC文件实现元素的动态交互。具体包括使用自定义HTML标签触发JavaScript函数的方法,以及如何通过鼠标悬停、移出和点击事件来改变页面元素的样式。
HTML文件:
None.gif<html>
None.gif
<head>
ExpandedBlockStart.gifContractedBlock.gif
<script type="text/javascript">dot.gif
InBlock.gif
function showCmd()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    alert(
"Ok");
ExpandedBlockEnd.gif}

None.gif
</script>
None.gif
<xml:namespace prefix="BNet">
None.gif
<?IMPORT namespace="BNet" implementation="a.htc">
None.gif</head>
None.gif<body>
None.gif<BNet:Cmd onCmd="showCmd()">
None.gif命令内容
None.gif</BNet:Cmd>
None.gif</body>
None.gif</html>
HTC文件:
None.gif<public:component tagName="Cmd">
None.gif
None.gif
<public:event id = "rcCmdId" name="onCmd"/>
None.gif
<public:attach event="onmouseover" onevent="mouseOver()" />
None.gif
<public:attach event="onmouseout" onevent="mouseOut()" />
None.gif
<public:attach event="onclick" onevent="doCmd()"/>
None.gif
<public:attach event="ondocumentready" onevent="htcInit()" />
None.gif    
None.gif
</public:component>
None.gif    
ExpandedBlockStart.gifContractedBlock.gif
<script type="text/javascript">dot.gif
InBlock.gif
function doCmd()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var oEvent = createEventObject();
InBlock.gif    rcCmdId.fire(oEvent);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function htcInit()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    setAttribute(
"__htc_changed",new Object()); 
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function set(prop,val)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    __htc_changed[prop] 
= eval(prop);
InBlock.gif    eval(prop 
+ "='" + val + "'");    
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function reset()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
for(var prop in __htc_changed)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        eval(prop 
+ "='" + __htc_changed[prop] + "'");
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
function mouseOver()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    set(
"style.color","#ff0000");
InBlock.gif    set(
"style.cursor","hand");
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function mouseOut()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    reset();
ExpandedBlockEnd.gif}

None.gif
</script>
None.gif

转载于:https://www.cnblogs.com/iyond/archive/2006/03/17/352393.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值