javascript - Javascript Click 按钮在 Chrome 中有效,但在 IE 中无效
问题描述
请检查 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>
提前致谢
解决方案
推荐阅读
- openapi - 如何更改“APIClient”名称
- java - 是否可以在 MapDB 中创建集群?
- css - 如何在 Wordpress 的帖子导航小部件中的帖子标题之间添加空格(最好使用一些 CSS)?
- c# - 当用户在 AccptsReturn="True" 的 WPF 文本框中按下 ENTER 键时如何避免换行
- javascript - 当我单击 FullCalender 的下一个、上一个、上一个月份按钮时,如何调用 ajax 请求?
- angular - Angular 11 - 找不到手动创建的语言环境文件
- python - 使用 pandas 根据来自另一个数据帧的行值填充列值
- java - 双向一对一映射仅以一种方式工作
- vue.js - 一个 POST 请求但不是另一个 POST 请求的 CORS 问题
- mongodb - 为什么在 Mongodb (PyMongo) 中数据加载为 Nan