2010-09-13 29 views
1

並進行以下測試。該測試具有一個初始函數,用於捕獲表單中的「submit」事件,因此submit btn調用window.addEvent函數。這工作。javascript - 使用mootools從不同的javascript函數調用javascript addEvent函數

我想弄清楚如何從一個單獨的javascript函數,即saveCollegedata函數調用window.addEvent函數。

通過網絡查看網站,還沒有拿出正確的方法來做到這一點。雖然關於做一個document.forms ['myform']。提交(),但這是行不通的。

也想到做一個onSubmit從窗體和調用不同的JavaScript函數,但不太確定如何這將起作用,以便能夠在ajax回調中使用「this.send」。

function saveCollegeData() 
    { 
     var t; 
     t="tt"; 
     alert("t="+t); 
//   window.top.fireEvent('domready'); 
//   document.forms["adminForm"].submit(); 
     t="tt"; 

    } 

    //-generate the 2nd coldata frm to mod the data 
    //-uses the mod-collegedata1.frm page 
    //-user confirms the data 
    window.addEvent('domready', function() { 

    $('adminForm').addEvent('submit', function(e) { 
     //Prevents the default submit event from loading a new page. 
     new Event(e).stop(); 
     //alert (foo); 
     alert ('11111111aaaa '); 
     //--clear out the div to start.. just in case.. 
     clearJorge(); 

     //--set/reset the task item to the task for 
     //--the server side.. was set to "" for the toolbar 
     //-- the "this" should refer to the $('adminForm') form 
     this.task.defaultValue="mdata2"; 
     . 
     . 
     . 

回答

1

使用fireEvent()方法(http://mootools.net/docs/core/Element/Element.Event#Element:fireEvent

$("adminForm").fireEvent("submit");

$("adminForm").submit();也應努力

有可能需要在對象上通過這樣與fireEvent()一個機會:

element.fireEvent("submit", { 
    stop: Function.from 
}); 

如果您在回調中有event.stop(),則會執行此操作。同樣,event.target或其他可能引用的屬性都需要進行模擬。

雖然有些事情對於1.2.x更有效,而你可能在1.1x的地方通過Event對象實例。