简体   繁体   English

如何使document.forms [0] .submit()工作?

[英]how to make document.forms[0].submit() work?

After i implemented my dialog box as a alert measure for user to confirm submission instead of a direct submission upon clicking, my document.forms[0].submit() does not work anymore. 在我将对话框实现为用户确认提交而不是单击后直接提交的警报措施之后,我的document.forms [0] .submit()不再起作用。 The page refreshes and the page stays the same. 页面刷新,并且页面保持不变。 Before that dialog box was created, everything works perfectly. 在创建该对话框之前,一切工作正常。 what is the problem here? 这里有什么问题?

After: 后:

  <script>
   //trigger dialog
 $('#submitIter').click(function(){
    $("#dialog-submit").dialog("open");
                return false
});

$("#dialog-submit").dialog({            
    autoOpen: false,
    resizable: false,
    height: 200,
    width: 200,
    modal: true,
    buttons: {
        "Proceed": function(){
            //submit after user clicks proceed cannot seem to work
            document.forms[0].submit();
            $(this).dialog("close");

        }
    }
});
   </script>

    <form action="{{ request.path }}" method="post" enctype="multipart/form-data">

      <input type="image" src="images/submit.png" id="submitIter">

    </form>

Before: 之前:

<script> document.forms[0].submit() </script>

I think you add some form before this one, try to write document.forms[1].submit(); 我认为您在此表单之前添加了一些表单,请尝试编写document.forms [1] .submit();。 Anyway as I can see you using jQuery, so you can write it this way: 无论如何,我可以使用jQuery看到您,因此可以这样编写:

<script>
   //trigger dialog
 $('#submitIter').click(function(){
    $("#dialog-submit").dialog("open");
                return false
});

$("#dialog-submit").dialog({            
    autoOpen: false,
    resizable: false,
    height: 200,
    width: 200,
    modal: true,
    buttons: {
        "Proceed": function(){
            //submit after user clicks proceed cannot seem to work
            $('#form_for_submit').submit();
            $(this).dialog("close");

        }
    }
});
   </script>

    <form id="form_for_submit" action="{{ request.path }}" method="post" enctype="multipart/form-data">

      <input type="image" src="images/submit.png" id="submitIter">

    </form>

It may have something to do with scoping or potentially another form being added by the dialog. 它可能与作用域或对话框可能添加的其他表单有关。 My first debugging step would be to wrapp document.forms[0] into an alert and see if it returns an object. 我的第一个调试步骤是将document.forms [0]包装到警报中,看看它是否返回对象。 Secondly I would give the form tag an id to explicity reference it eg id="mainForm" then you can do document.getElementById("mainForm").submit(); 其次,我将给表单标签一个ID以明确引用它,例如id =“ mainForm”,然后您可以执行document.getElementById("mainForm").submit();

Or you could write it as the other answer suggests 或者您也可以将其写为其他答案

$("#mainForm").submit();

Also try calling the dialog close command first. 另外,请尝试先调用对话框关闭命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何知道document.forms [&#39;aspnetForm&#39;]。submit()在服务器端进行提交? - How to know document.forms['aspnetForm'].submit() make the submit at the server side? using document.forms [“MbrForm”]。submit(); 不起作用 - using document.forms[“MbrForm”].submit(); does not work javascript:document.forms [0] .submit()不适用于IE10 - javascript:document.forms[0].submit() does not work with IE10 document.forms[“button1”].submit() 在计时器到期时不起作用 - document.forms[“button1”].submit() not work when timer expired 如何使用 .submit() 提交带有 document.forms 对象的表单 - How to use .submit() to submit a form with document.forms object 如何防止 document.forms[0].submit() 提交表单? - How to prevent document.forms[0].submit() from submitting a form? 当使用“javascript:document.forms [0] .submit()”时如何调用“onsubmit”? - How to call “onsubmit” when “javascript:document.forms[0].submit()” is used? document.forms [0] .submit()有什么问题? - What is wrong with document.forms[0].submit()? 是否可以在 JMeter 中执行 document.forms[0].submit()? - Is it possible to execute document.forms[0].submit() in JMeter? “ document.forms不是函数”和“ document.forms(0)” - “document.forms is not a function” with “document.forms(0)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM