0

我有一个要放在网页上的表单,我的大多数用户都将使用 IE。顶部有一系列单选按钮,当其中任何一个被选中时,下面的表单应该会发生变化。这是代码:

<html>
<head>
<script language="javascript">
function prepareForm() {
  var t = document.getElementById('top');
  document.getElementById('search1').style.top = t.style.top + t.style.height;
  document.getElementById('search2').style.top = t.style.top + t.style.height;
  document.getElementById('search3').style.top = t.style.top + t.style.height;
}
function displayForm() {
  var a = document.getElementsByName('search');
  var b = document.getElementsByName('searchBy');
  for (i=0;i<a.length;i++) {
    if (!b[i].checked) {
      a[i].style.display="none";
    } else {
      a[i].style.display="block";
    }
  }
}
</script>
</head>
    <body style="font-family:calibri;text-align:center;" onLoad="displayForm();">
<div id="top">
<center><h3>My webpage</h3></center>
<br>
<form method="post" action="results.html" name='myForm'>
<center><font face='calibri'>Search By:</center><br>
<center>
<input type="radio" name="searchBy" value="search1" checked onClick="displayForm();">Form one
<input type="radio" name="searchBy" value="search2" onClick="displayForm();">Form two
<input type="radio" name="searchBy" value="search3" onClick="displayForm();">Form three
</div>

<!-- search area 1 -->
<div name="search" id="search1" style="margin-left:auto;margin-right:auto;display:block;">
<p>Form 1</p>
<input type="Submit" value="Submit">
</div>

<!-- search area 2-->
<div name="search" id="search2" style="margin-left:auto;margin-right:auto;display:none;">
<p>Form 2</p>
<input type="Submit" value="Submit"></b>
</div>

<!-- search area 3 -->
<div name="search" id="geoSearch" style="margin-left:auto;margin-right:auto;display:none;">
<p>Form 3</p>
</div>

</body>
</html>

此代码似乎在 Chrome 中工作,但在 IE9 中,调用 javascript 函数时显示的内容不会改变displayForm()。IE9和Chrome之间的divstyle.display属性有什么不同吗?

4

1 回答 1

0

如果你真的需要帮助,首先搜索一下为什么IE 会出现 document.getElementByID 错误

来自: http: //msdn.microsoft.com/en-us/library/ie/ms536437%28v=vs.85%29.aspx

此方法对 ID 和 NAME 属性执行不区分大小写的匹配,这可能会产生意外结果。

在阅读了一些关于它的内容、验证 a<!doctype>后,尝试替换您的“姓名”和“身份证”,以便它们匹配,然后对其进行测试,然后返回此处提供详细信息和更多信息,以便我们可以尝试为您提供更多帮助。

PostScriptum:当我读到:“我不知道 HTML 4 中的语言属性已过时”时,感觉就像是该死!我是否在浪费时间试图帮助那些在 Web UI 开发职业中永远不会成长的人,没有全心全意地做功课,并且最有可能成为Stackoverflow 上的“复制粘贴”来要求“这样做是因为我不能'。

于 2013-09-23T17:00:14.613 回答