首页 > 解决方案 > Javascript Click 按钮在 Chrome 中有效,但在 IE 中无效

问题描述

下面是来自 IE 的 Console.log 的图片。 如果它没有帮助,请让我知道我还能得到什么日志请检查 Javascript 代码,看看为什么它在 Chrome 中运行良好,但在 IE11 中运行良好。当我单击按钮创建文本框时,文本框是在 Chrome 中创建的,而不是在 IE11 中创建的。

当我单击按钮时,它会垂直创建文本框。还请让我知道如何在每个文本框之间创建空间。

<script type="text/javascript">
    var counter = 0;
    function addNew() {
        // Get the main Div in which all the other divs will be added
        var mainContainer = document.getElementById('mainContainer');
        //mainContainer.style.left = '500px';
        // Create a new div for holding text and button input elements
        var newDiv = document.createElement('div');
        // Create a new text input
        var newText = document.createElement('input');
        newText.type = "input"; 
        //newText.value = counter;
        newText.name = "choiceEntry";
        newText.style.height = '40px';

        newText.size = "100";
        // Create a new button input
        var newDelButton = document.createElement('input');
        newDelButton.type = "button";
        newDelButton.value = "Delete";

        // Append new text input to the newDiv
        newDiv.appendChild(newText);
        // Append new button input to the newDiv
        newDiv.appendChild(newDelButton);
        // Append newDiv input to the mainContainer div
        mainContainer.appendChild(newDiv);
        counter++;

        // Add a handler to button for deleting the newDiv from the mainContainer
        newDelButton.onclick = function() {
            mainContainer.removeChild(newDiv);
        }
    }
</script>

在 JSP 按钮中:

<div>
    <input type="text" class="bigText" value="<%=choice.getChoiceEntry()%>" size="100" name="choiceEntry" />
    <input type="button" value="Add" onClick="addNew()">
</div>

提前致谢

标签: javascript

解决方案


推荐阅读