2012-08-22 60 views
0

我想通过点击一个按钮来“激活”其他两个按钮的点击。 我已经把这个ccjs在onclick事件:通过点击一个按钮调用另外两个按钮

document.getElementById("#{id:button28}").click();document.getElementById("#{id:button29}").click(); 

但后来唯一的按钮28被点击! 然后,我试着将这部分代码放在onclick事件和part2下的onmousedown事件之下。然后,我必须在他实际完成这项工作之前点击此按钮2次。

至今代码:

<xp:button value="Save" id="button26"> 
<xp:eventHandler event="onclick" submit="false"> 
    <xp:this.script> 
     <xp:executeClientScript> 
    <xp:this.script><![CDATA[document.getElementById("#{id:button29}").click(); 
    ></xp:this.script> 
     </xp:executeClientScript> 
    </xp:this.script></xp:eventHandler></xp:button><xp:button id="button29" value="button29"> 
    <xp:eventHandler 
    event="onclick" submit="true" refreshMode="partial" 
    id="eventHandler21" refreshId="outsidePanel5"> 
     <xp:this.action> 
      <xp:actionGroup> 
       <xp:executeScript> 
       <xp:this.script><![CDATA[#{javascript:sessionScope.put("test","");// and some more code}]]> 
       </xp:this.script> 
       </xp:executeScript> 
      </xp:actionGroup> 
     </xp:this.action> 
    <xp:this.onComplete><![CDATA[document.getElementById("#{id:button28}").click();]]></xp:this.onComplete> 
    </xp:eventHandler></xp:button><xp:button value="button28" id="button28"> 
    <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="outsideMogelijkheid"> 
     <xp:this.action> 
      <xp:executeScript 
        script="#{javascript://some code}"> 
      </xp:executeScript> 
     </xp:this.action> 
    </xp:eventHandler></xp:button> 

回答

0

如果这些按钮执行您需要添加代码,点击第二个按钮,第一个按钮的 的onComplete事件SSJS代码。

http://xpagesblog.com/XPagesHome.nsf/Entry.xsp?documentId=0574D334CB03EACF852578CB00667F54

加成 工作示例的onComplete的不在于它只有局部刷新

<xp:button value="Save" id="button26"> 
<xp:eventHandler event="onclick" submit="false"> 
    <xp:this.script><![CDATA[document.getElementById("#{id:button29}").click()]]> 
</xp:this.script> 
    </xp:eventHandler></xp:button> 
<xp:button id="button29" value="button29"> 

<xp:eventHandler event="onclick" submit="true" 
    refreshMode="partial" refreshId="computedField1"> 

    <xp:this.action><![CDATA[#{javascript:viewScope.test="Almost Done"}]]> 
</xp:this.action> 
    <xp:this.onComplete> 
<![CDATA[document.getElementById("#{id:button28}").click();]]> 
</xp:this.onComplete> 
    <xp:this.onError><![CDATA[alert("error")]]></xp:this.onError> 
</xp:eventHandler></xp:button> 

<xp:button value="button28" id="button28"> 
    <xp:eventHandler event="onclick" submit="true" 
refreshMode="partial" refreshId="computedField1"> 

     <xp:this.script><![CDATA[alert("Button 28")]]></xp:this.script> 
     <xp:this.action> 
      <xp:executeScript> 
       <xp:this.script><![CDATA[#{javascript:viewScope.test="Done"}]]> 
</xp:this.script> 
      </xp:executeScript> 
     </xp:this.action></xp:eventHandler> 
</xp:button> 
<xp:br></xp:br> 
<xp:text escape="true" id="computedField1" value="#{viewScope.test}"></xp:text> 
+0

我不认为我明白该怎么做。我尝试了以下操作:在第一个按钮的oncomplete事件中,我放了document.getElementById(“#{id:button28}”)。click();所以在sourcepanel中我得到:<![CDATA [document.getElementById(“#{id:button28}”)。click();]]>一个错误,他无法找到点击属性的值。 –

+0

你可以发布你的问题的xpage源,然后我可以更正源。 –

+0

编辑的第一篇文章代码 –

1

如果你想在另一个按钮运行SSJS工作,实际上你可以调用eventHandler以编程方式而不是触发CSJS中的按钮。这也会表现得更好,因为你不会一直在CSJS和SSJS之间切换。下面的代码应该工作:

var eventHandler:com.ibm.xsp.component.xp.XspEventHandler = getComponent("button29"); 
eventHandler.getAction().invoke(facesContext, null); 
eventHandler = getComponent("button28"); 
eventHandler.getAction().invoke(facesContext, null); 
+0

作品也谢谢! –

+0

作为更好的方法,使用组件绑定,请参见http://www.intec.co.uk/triggering_an_eventhandler_from_another_button/ –

相关问题