2012-08-22 225 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/ –

相關問題