onclick 属性

       

返回或设置 Variant 值,该值代表与 onclick 事件相关联的值。例如,Variant 可以代表当事件发生时执行的的某个宏或过程调用。可读写。

expression.onclick

expression  必选。返回 DispFPHTMLDocument 对象的表达式。

示例

下列示例在用户单击当前网页中包含 onclick="DisplayMessage" 的 <p> 元素时,向用户显示一条消息。该示例内嵌在 HTML 文档的 <head> 节中。

<head>
<title>onclick Example</title>
<script id=clientEventHandlersVBS language=vbscript>
<!--

Sub DisplayMessage
'Displays message to user

    MsgBox "This message is displayed when the user clicks the <p> element in the current document."

End Sub

-->
</script>
</head>

下面的 <p> 节代码将调用位于文档的 <head> 节中的 DisplayMessage 过程。当用户单击文档中的 <p> 元素时,将显示一条信息。

<body>
<p onclick = "DisplayMessage">Click this paragraph to view a message.</p>
</body>

下列代码行将 onclick 属性设置为 DisplayMessage 过程调用。索引值 zero (0) 表示<p> 标记是当前网页中唯一的 <p> 元素,也是 all 集合中唯一的 <p> 元素。

ActiveDocument.body.all.tags("p").item(0).onclick = "Display Message"