【问题标题】:Why won't IE8 submit a form?为什么 IE8 不提交表单?
【发布时间】:2014-02-10 22:47:43
【问题描述】:

我正在开发一个专门针对 IE8 的小型 Web 应用程序(我知道你们都已经感受到了痛苦)。在这个应用程序中,我有一个 Update“按钮”(单击时)会生成一个框,用户可以在其中单击 YesNo。我使用 JavaScript 生成框和带有type="submit"input 标记。

这是一个sn-p的代码:

HTML

<form action="." method="POST" id="yield_curve_form" enctype="multipart/form-data">
    <div class="fileUploadDiv">
        <img id="yieldCurve" src="../img/market/yield_curve.jpg" alt="ZBPF Bond Market" >    
        <div class="fileUploadButton">
            <span>Upload New Image</span>
            <input type="file" name="image_file" accept="image/*" class="uploadInput">
        </div>
        <div class="fileUploadReq">    
            <p>Image Requirements:</p>
            <ul>
                <li>Format: .png, .jpg, .jpeg, .bmp, .tif, .tiff</li>
                <li>Resolution: 650 x 383</li>
                <li>Maximum size: 2.0 MB</li>
            </ul>
        </div>
    </div>
    <button type="button" class="marketUpdateButton" onclick="confirmUpdate('yield_curve');">Update</button>

JS

function confirmUpdate(name)
{
    //  Create a div element
    var div = document.createElement('div');
    //      Give it an ID
    div.id = 'preSubmitAlert';

    //  Create a child h2 tag
    var h2 = document.createElement('h2');
    h2.innerHTML = 'This is a permanent change';
   //  Create a child p tag
   var pMessage = document.createElement('p');
   pMessage.innerHTML = 'Did you double check the data? It is important the data is     accurate before you submit it.';
   //  Create child input tags
   var inputYes = document.createElement('input');
   var inputNo = document.createElement('input');
   //      Set parameters for input tags
   inputYes.type = 'submit';
   inputYes.name = name + '_update';
   inputYes.value = 'Yes. Update the data.';
   inputYes.id = 'inputYes';
   inputNo.type = 'button';
   inputNo.value = 'No. Take me back, please.';
   inputNo.id = 'inputNo';

   //  Append the children to 
   div.appendChild(h2);
   div.appendChild(pMessage);
   div.appendChild(inputYes);
   div.appendChild(inputNo);

   //  Create the background for transparency (needed for IE8 support)
   var bg_div = document.createElement('div');
   bg_div.id = 'bg_div';

   //  Create a screen and append the above div to it
   var screenDiv = document.createElement('div');
   screenDiv.id = 'screenDiv';
   //      Appending div and bg_div to screenDiv
   screenDiv.appendChild(div);
   screenDiv.appendChild(bg_div);
   //      Appending screenDiv to the body tag
   document.body.appendChild(screenDiv);
   //      This line needs a reference to the #screenDiv is, which is inserted in the DOM only in the above line.
   inputNo.onclick = function(){destroyElement(document.getElementById('screenDiv'))};
   inputYes.setAttribute('form', name + '_form');
}

问题

为什么&lt;input type="submit" ...&gt;点击后不提交数据?

Obs.:这段代码适用于所有其他浏览器,包括更高版本的 IE。

提前谢谢你。

【问题讨论】:

  • screenDiv 附加到表单中,而不是document.body

标签: javascript internet-explorer-8 forms http-post


【解决方案1】:

改变这个...

document.body.appendChild(screenDiv);

到这里……

document.getElementById(name + '_form').appendChild(screenDiv);

我非常怀疑 IE8 是否支持 HTML5 form 属性,因此您需要将提交按钮设置为表单的后代。

不过,我找不到任何官方文档,而且我怀疑有人会费心去正确研究它。

【讨论】:

  • 这确实是正确的做法。不同之处在于document.getElementById(name + '_form').appendChild(screenDiv); 将使代码适用于页面内的其他表单(但我没有在问题中指定)。谢谢你,先生。没错,IE8 不支持form 属性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 2014-04-13
  • 2016-06-08
  • 2015-01-16
  • 1970-01-01
  • 1970-01-01
  • 2019-03-08
相关资源
最近更新 更多