Javascript 新插入表单上的原型提交事件处理

Javascript 新插入表单上的原型提交事件处理,javascript,events,prototype,Javascript,Events,Prototype,我在一个页面上有许多可点击的图像/按钮,它们有以下内容(使用Prototype.js) 还有其他人有这个 $$( '.lbrinq' ).each( function ( name ) { name.observe( 'click' , function ( ev ) { var form = new Element( 'form', { m

我在一个页面上有许多可点击的图像/按钮,它们有以下内容(使用Prototype.js)

还有其他人有这个

$$( '.lbrinq' ).each( function ( name ) {
    name.observe( 'click' , function ( ev ) {
        var form = new Element( 'form',
                                {
                                  method: 'post',
                                  action: 'url'
                                });

            form.insert(new Element( 'input',
                                  {
                                    name: 'document',
                                    value: $(this).down("input[name=document]").value,
                                    type: 'hidden'
                                  }));

             $(document.body).insert(form);
             form.submit(); 

    });
});
两者类似,但一个创建一个模式表单,在提交前请求用户输入,另一个创建表单元素,并在单击按钮/图像时实际提交表单

我需要添加一个提交事件处理程序,以便只允许一次表单提交。由于这些表单是动态创建的,所以我尝试的一切都以这样或那样的方式失败了

我试过换衣服

    var form = new Element( 'form',
                            {
                              method: 'post',
                              action: 'url'
                            });

我还尝试将提交侦听器添加到文档中

 document.observe( 'submit', function( e, el ) {

    if ( el = e.findElement( 'form' ) ) {

          // Disable  all submit buttons
          $$( 'input[type="submit"]' ).invoke( 'disable' );         

          // If no previous submissions detected go ahead
            if( subck == 0){
              // show loading graphic to user
              $('processing_gif').show();

                  subck = 1;
                 return true;  // jump out of logic to continue normal operation
            } else { // Previous submission detected

              // Stop right here to prevent multiple submissions.
                e.stop();       
        }
    }
  });
这在firefox中有效,但在IE8/9中不起作用


有人对如何在动态创建的表单上处理“提交”事件有什么建议吗?

如果您向DOM添加元素,则不会有任何事件连接到新元素上——您必须在新元素插入DOM后附加它们。
form.observe(“submit”,function(){alert(“hi”);})
$(document.body)之后插入(表单)不起作用,但我的问题可能是如何引用元素。
    var form = new Element( 'form',
                            {
                              method: 'post',
                              action: 'url',
                              onsubmit: 'alert("hi");return false;'
                      //also  onsubmit: function(){ alert("hi" ); }

                            });
 document.observe( 'submit', function( e, el ) {

    if ( el = e.findElement( 'form' ) ) {

          // Disable  all submit buttons
          $$( 'input[type="submit"]' ).invoke( 'disable' );         

          // If no previous submissions detected go ahead
            if( subck == 0){
              // show loading graphic to user
              $('processing_gif').show();

                  subck = 1;
                 return true;  // jump out of logic to continue normal operation
            } else { // Previous submission detected

              // Stop right here to prevent multiple submissions.
                e.stop();       
        }
    }
  });