简体   繁体   English

IE11中的表单提交无法正常工作

[英]Form submit in IE11 doesn't work correctly

I have a problem with the form onsubmit function in IE 11. When the submit button was triggered, the "doSomething()"-function will be called. IE 11中的表单onsubmit函数存在问题。触发提交按钮时,将调用“ doSomething()”函数。 Inside the "doSomething()" function I call another function that does some input-validation stuff. 在“ doSomething()”函数中,我调用另一个函数,该函数执行一些输入验证的工作。 This function always returns false but sets a flag to true if all validation errors are gone. 此函数始终返回false,但如果所有验证错误均已消失,则将标志设置为true。 If the flag was set to true, the "doSomething()"-function returns true and the form will be submitted and the action is called. 如果该标志设置为true,则“ doSomething()”函数将返回true,并且将提交表单并调用该动作。 This pattern works in Firefox, Chrome and Safari but doesn't in IE11. 这种模式在Firefox,Chrome和Safari中有效,但在IE11中则无效。 In IE it calls the action before the "doSomeValidation()"-Function is ready. 在IE中,它会在“ doSomeValidation()”功能就绪之前调用操作。 :-/ Can anybody help me out here? :-/有人可以帮我吗? Thanks a lot!!! 非常感谢!!!

<form action="headToNextPage.php" onsubmit="return doSomething()">

js JS

flag = false, // a global flag inside the js-script

function doSomeValidation(){
// validate the inputs and set "flag" to true if all errors are gone
}

function doSomething(){
   doSomeValidation(); // do the validation stuff

   if(flag==true) {
   // do some other stuff
     return true
   }

   return false;
}

将false替换为半冒号后替换逗号,并在其在IE11中起作用的dosomething方法内添加一些警报,请确保flag = false;

I solved it. 我解决了 Problem was, that I called the JS .startsWith(..)-function on a string inside of the jQuery $( document ).ready(..)-function. 问题是,我在jQuery $(document).ready(..)函数内部的字符串上调用了JS .startsWith(..)函数。 Chrome, Firefox and Safari ignored it, but IE went crazy with it but didn't show any errors. Chrome,Firefox和Safari忽略了它,但是IE对其疯狂,但是没有显示任何错误。 I took the .indexOf(..)-function instead and it worked. 我改用了.indexOf(..)-函数,它起作用了。 thanks to all for helping me out here! 感谢所有人在这里帮助我!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM