我的页面上有 2 个表单。
第一个始终可见,第二个首先隐藏。
当用户单击指定的单选选项时,会显示第二个表单。
在 Chrome 和 Firefox 中,一切正常,但在 IE 中,表单显示,但我无法在文本框字段内写入。
最奇怪的是,我可以删除文本框内的所有内容,但无法添加任何内容。
这是一些代码:
第一种形式:
<form name="calendar" action="" method="post">
<input type="text" name="n" />
<input type="radio" name="t" value="0" onclick="showSecondForm();" />Option 1
<input type="radio" name="t" value="1" onclick="showSecondForm();" />Option 2
<input type="radio" name="t" value="2" onclick="showSecondForm();" />Option 3
<input type="submit" name="submit" value="Submit" onclick="onSubmitAction();return false;">
</form>
函数 showSecondForm() 检查选项 3 是否被选中,如果是,则显示第二种形式。
第二种形式是:
<div id="customForm" style="display: none;">
<form name="custom" action="" method="post">
<input type="text" name="a" />
<input type="text" name="b" />
<input type="text" name="c" />
<input type="text" name="d" />
<input type="text" name="e" />
</form>
</div>
表单永远不会提交,因为我必须做的一切都在 javascript 中,而且我可以轻松访问这两个表单。除了在 ie 中的文本框中键入内容外,我的所有代码都工作正常。
我的javascript
<script type="text/javascript">
function showSecondForm()
{
if(document.calendar.t[2].checked)
{
document.getElementById('customForm').style.display = 'block';
}
else
{
document.getElementById('customForm').style.display = 'none';
}
}
</script>
最佳答案
在 Google Chorme 和 Mozilla Firefox 等浏览器中,当您将文本输入字段的最大长度设置为 0 时,文本框的长度为“无限制”。在 Internet Explorer 中,它实际上是 0,因此您不能在其中写入任何内容。
所以代码必须是:
<div id="customForm" style="display: none;">
<form name="custom" action="" method="post">
<input type="text" name="a" maxlength="255" />
<input type="text" name="b" maxlength="255" />
<input type="text" name="c" maxlength="255" />
<input type="text" name="d" maxlength="255" />
<input type="text" name="e" maxlength="255" />
</form>
</div>
关于javascript - HTML - 我无法在 Internet Explorer 中由 javascript 动态显示的某些文本框中写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180548/