【问题标题】:javascript:document.forms[0].submit() does not work with IE10javascript:document.forms[0].submit() 不适用于 IE10
【发布时间】:2013-06-18 23:46:31
【问题描述】:

我的代码:

<form method="post" action="PreDischargeEducation.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/lots of stuff here" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>
<div class="aspNetHidden">
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBgKblbSKDQLWxZaxDwK+n5yTDgKN97n9CAL1m+DgCwKZseiDBoE7ceDrS0JTSg/qHRKRiCdcZ+nF2M69ovt+U0TvDhOh" />
</div>

然后在底部我有

<a class="box" href="javascript:document.forms[0].submit()">Submit &amp; Continue...</a>

但是,按钮不走。表单[0]在IE10中不可用吗?

另外,当我在字段中使用 Return 键提交时,数据似乎没有进入后端 ASP.NET 代码。我的 JavaScript 不好吗?在其他浏览器中运行良好。

编辑:标签在实际代码中。

【问题讨论】:

  • form 标签在哪里关闭?
  • 建议在form 关闭后移动脚本
  • 我没有附上 但它在 之后
  • 问题解决了吗
  • 我只是说我没有将它包含在上面的代码中,而是在真实的代码中。

标签: javascript forms internet-explorer post postback


【解决方案1】:

我能够通过在 setTimeout 中包装 jQuery 表单提交来解决这个噩梦般的问题:

$('#complete_profile input[type="submit"]').click(function(){
  setTimeout(function() {
    $('#complete_profile form').submit();
  }, 0);
});

但是,当表单确实提交时,这可能会导致重复提交,所以要小心。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多