JavaScript Mootools回调

时间:2011-04-22 18:48:03

标签: javascript callback mootools

如何将我的回电注册回Mootools中的formRegister。

http://mootools.net/docs/more/Forms/Form.Validator

  

//验证。
  new Form.Validator.Inline(myForm,{     formValidate:myCallback});

     

function myCallback(){alert(“form   有效“)}

1 个答案:

答案 0 :(得分:1)

这是一种做法。从Mootools演示中,您可以通过附加onSuccess回调来执行以下操作:

window.addEvent('domready', function(){

    // The elements used.
    var myForm = document.id('myForm'),
        myResult = document.id('myResult');

    // Labels over the inputs.
    myForm.getElements('[type=text], textarea').each(function(el){
        new OverText(el);
    });

    // Validation.
    new Form.Validator.Inline(myForm);

    // Ajax (integrates with the validator).
    new Form.Request(myForm, myResult, {
        requestOptions: {
            'spinnerTarget': myForm
        },
        extraData: { // This is just to make this example work.
            'html': 'Form sent.'
        },
        onSuccess: function(result){  //callback function added to demo
            console.log(result);
        }
    });
}