Mootools构建形式

时间:2010-01-18 17:04:02

标签: javascript mootools

所以我试图在mootools中创建一个自定义的编辑器,我想使用一个表单。每当我尝试创建一个表单时,它只会创建<form class="inplaceeditor-form" method="post" action="#"/>如何将其作为一个可以注入其他元素的表单?

1 个答案:

答案 0 :(得分:2)

您必须创建其他输入元素才能进入表单内部。 像这样的东西:

   // create the form element
   var form = new Element('form', {'action' : 'your/action', 'class' : 'inplaceeditor-form'});
  //create the textbox
   var textarea = new Element('textarea', {'name' : 'myTextarea'});
    //create the submit button  
 var button = new Element('input', {'type' : 'submit', 'value' : 'Submit Me!'});
   // this puts the textarea and the button into the form
   form.adopt(textarea,button);
   // put the form inside what ever container you user
    $('myContainer').adopt(form);

   // the code above should give you this
   <div id="myContainer">
       <form action="your/action" method="post" class="inplaceeditor-form">
            <textarea name="myTextarea"></textarea>
            <input type="submit" value="Submit Me!" />
      </form>