2010-09-26 105 views
1

我試圖用javascript/jquery點擊面板拆分器collaplse /展開按鈕,無濟於事。如何以編程方式觸發點擊事件?

這裏是分路器的一個例子:http://jdevadf.oracle.com/adf-richclient-demo/faces/components/index.jspx;jsessionid=GTYNMf7Mq2JD6L4v38yCdTh2HLplhJYLTGc1J1TjZFwmpZjcqh1n!-294683649?_afrLoop=28596129526428344&_afrWindowMode=0&_afrWindowId=null#%2Fcomponents%2FpanelSplitter.jspx%40

正如你所看到的,當你點擊的小按鈕的箭頭,該區域的崩潰。如果我嘗試獲取元素並單擊它,則什麼都不會發生。

$("dmoTpl:innerVerticalSplitter::i").onclick() 

如果我加載jQuery腳本並觸發點擊,也沒有任何反應。我有點困惑這是如何工作,爲什麼腳本點擊被忽略。有任何想法嗎?

回答

0

它是點擊()不是onclick()與jQuery,但是當我檢查你的代碼$不是jQuery。你確定這個頁面上有jQuery嗎?

+0

從鏈接頁面不使用jquery,no。我正在開發一個ADF項目,我的頁面可以使用它,但我不認爲有任何使用這兩個項目的公開演示。 – jernej 2010-09-26 21:53:14

0

而不是試圖創建一個點擊事件,如果你知道事件處理程序,直接直接調用該方法通常會更好。這裏是jQuery中的一個例子。事件處理程序

var clickEventHandler = function(event) { 
    ... 
}; 

$('#some-button').click(clickEventHandler); 

編程調用它的

安裝後

clickEventHandler(); 
+0

關鍵是,我只想模仿用戶點擊從JavaScript/jQuery的。 「dmoTpl:innerVerticalSplitter :: i」似乎是這樣做的錨點,但我並不真正瞭解它的工作原理。從jquery調用點擊它什麼都不做。 這是按鈕的html: Bereich ausblenden jernej 2010-09-26 22:10:07

1

我不使用JQuery,但這裏是用香草JavaScript和<af:clientListener/>標記,工作的例子。

<?xml version='1.0' encoding='UTF-8'?> 
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich" xmlns:f="http://java.sun.com/jsf/core"> 
    <af:resource type="javascript"> 
    function toggleSplitter(evt) { 
     comp = evt.getSource().findComponent('ps1'); 
     if (comp) { 
      comp.setProperty("collapsed", !comp.getProperty("collapsed")); 
     } 
     else { 
      alert('not found'); 
     } 
    } 
    </af:resource> 
    <af:panelStretchLayout id="psl1"> 
    <f:facet name="center"> 
     <af:panelSplitter id="ps1"> 
     <f:facet name="first"> 
      <af:outputText value="First" id="ot1"/> 
     </f:facet> 
     <f:facet name="second"> 
      <af:panelFormLayout id="pfl1"> 
      <f:facet name="footer"/> 
      <af:commandButton text="Toggle" id="cb1" immediate="true"> 
       <af:clientListener method="toggleSplitter" type="click"/> 
      </af:commandButton> 
      <af:outputText value="Second" id="ot2"/> 
      </af:panelFormLayout> 
     </f:facet> 
     </af:panelSplitter> 
     <!-- id="af_one_column_stretched" --> 
    </f:facet> 
    </af:panelStretchLayout> 
</jsp:root> 

之前點擊它展開:

alt text

,並單擊它合攏後:

alt text

0

您可以使用jQuery的元素上觸發一個事件。考慮觸發各種事件的下面的代碼。

$('#myElement').trigger('click'); 
$('#myElement').trigger('mousedown'); 
$('#myElement').trigger('touchstart'); 
相關問題