日期:2014-03-16  浏览次数:20755 次


<p><b>定义事件</b>
<p>要在 HTC 中定义一个事件,我们需要用到 PUBLIC:EVENT 元素。当我们定义了一个事件后,我们就可以在 HTC 的所在页中来调用它。
<p>在下面的例子中来示范如何实现一个计算器的功能。在 HTC 中我们使用 EVENT 元素定义了一个 onResultChange 事件。当在所在页中激活 onResultChange 事件时,HTC 将计算出结果并返回到所在页。
<xmp>
<PUBLIC:EVENT NAME=onResultChange ID=rcID />
<SCRIPT LANGUAGE="JScript">
:
oEvent = createEventObject();
oEvent.result = sResult;
rcID.fire (oEvent);
:
</SCRIPT>
</xmp>
<p>下面是含有这个 HTC 的页面:
<xmp>
<HTML XMLNS:InetSDK>
<HEAD>
<T99vLE>Calculator Sample</T99vLE>

<STYLE>
INPUT {font-family: Courier New}
@media all {
InetSDK:CALC {behavior:url(Engine.htc)}
}
</STYLE>

<LINK REL="stylesheet" HREF="/workshop/basicSDKIE4.css" TYPE="text/css">
</HEAD>

<BODY BGCOLOR="<BLOCKQUOTE CLASS="body">

<P>
<InetSDK:CALC id="myCalc" onResultChange="resultWindow.innerText =window.event.result">
<TABLE>
<TR>
<TD COLSPAN=5>
<DIV ID="resultWindow" STYLE="padding:5; background-color:buttonface" ALIGN="RIGHT">0.</DIV>
</TD>
</TR>
<TR>
<TD><INPUT TYPE=BUTTON VALUE=" 7 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 8 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 9 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" / "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" C "></TD>
</TR>
<TR>
<TD><INPUT TYPE=BUTTON VALUE=" 4 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 5 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 6 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" * "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" % " DISABLED></TD>
</TR>
<TR>
<TD><INPUT TYPE=BUTTON VALUE=" 1 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 2 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" 3 "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" - "></TD>
<TD><INPUT TYPE=BUTTON VALUE="1/x" DISABLED></TD>
</TR>

<TR>
<TD><INPUT TYPE=BUTTON VALUE=" 0 "></TD>
<TD><INPUT TYPE=BUTTON VALUE="+/-"></TD>
<TD><INPUT TYPE=BUTTON VALUE=" . "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" + "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" = "></TD>
</TR>
</TABLE>
</InetSDK:CALC>