文本“按下按钮 2”会在文档加载时添加到 log.nsf 中(即,将 URL 复制/粘贴到浏览器地址栏中时)。当我单击它时它也会运行,这是所需的行为。谁能告诉我发生了什么事吗?HCL 文档中没有关于onclick事件或事件处理程序的内容来描述此行为和/或如何阻止其发生。
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument formName="fParent" var="document1" />
</xp:this.data>
<xp:button value="Click me" id="button2" type="submit"
refreshMode="complete">
<xp:this.onclick><![CDATA[#{javascript:print("button 2 pressed");}
]]></xp:this.onclick>
</xp:button>
</xp:view>
Run Code Online (Sandbox Code Playgroud)
onclick是客户端事件,并且由于客户端事件包含服务器端代码,因此该代码在加载页面时运行。
如果您只想在单击按钮时运行服务器端代码,您应该action使用eventHandler.
所以你的按钮应该看起来像这样:
<xp:button value="Click me" id="button2">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print("button 2 pressed");}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Run Code Online (Sandbox Code Playgroud)