如何使用 Mootools 操作表单
我正在尝试使用 Mootools 操作表单。我的目的是将表单的响应内容注入到名为 result
的 div 元素中。
这里的代码可以工作,但它替换了 result
div 的内容。这不是我想要的:我想将表单响应内容添加到结果 div 现有内容中。我只是在网上找不到如何做到这一点,并且我尝试了很多不起作用的方法......请帮助
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();
});
});
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();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想添加文本,只需删除
empty
方法,并将result.set()
替换为result.appendText()
即可。如果您需要附加元素树,请重复第一步,然后执行以下操作:
顺便说一句。一切都在文档中 - http://mootools.net/docs/core/Element/Element
If it's only text you want to add, just remove the
empty
method, and replaceresult.set()
withresult.appendText()
.If you need to append an element tree, repeat the first step, and do:
Btw. It's all in the documentation - http://mootools.net/docs/core/Element/Element