开发者

How to manipulate forms with Mootools

开发者 https://www.devze.com 2023-02-21 06:27 出处:网络
I\'m trying to manipulate forms with Mootools. My purpose is to inject the response content of a form into a div element named result.

I'm trying to manipulate forms with Mootools. My purpose is to inject the response content of a form into a div element named result.

Here a code that works, but it replaces the content of the result div. This is not what I want : I want to ADD the form response content to the result div existing content. I just can't find on the web how to do this, and I've tried many things that are not working ... Please help

window.addEvent('domready', function() {      
  $('myform').addEvent('submit', function(e) {    
    e.stop();     
    var result = $('result').empty();      
   开发者_如何学运维 this.set('send',{    
        url: this.get('action'),    
        data: this,    
        onSuccess: function() {    
            result.set("html", this.response.text);    
        }    
    }).send();      
  });      
});      


If it's only text you want to add, just remove the empty method, and replace result.set() with result.appendText().

If you need to append an element tree, repeat the first step, and do:

onSuccess: function(){
    Elements.from(this.response.text).inject(result);
}

Btw. It's all in the documentation - http://mootools.net/docs/core/Element/Element

0

精彩评论

暂无评论...
验证码 换一张
取 消