0

这里是网页设计师新手,所以我希望这些术语是正确的,并且问题不会太尴尬。我得到的是一个包含 4 个项目的 html 表单(在 html5 文档中)(尽管还会有更多):

  1. 选择一个页面
  2. 第 1 页
  3. 第2页
  4. 第 3 页

…以及这 3 个页面中的每一页的文本,全部使用 CSS 隐藏。首次打开或刷新页面时,“选择页面”在表单菜单框中可见。当一个页面被选中时,“infobox.js”(我多年前在网上的某个地方)使该页面的文本在菜单框下方可见。完美运行。

我想要的是:第一次打开页面时,“选择页面”在表单菜单框中可见,并且第 1 页的文本已经在其下方可见。

我假设这是可能的,但我已经把头发扯掉了几天,希望解决方案对某人来说真的很容易。提前感谢您的帮助!

HTML

<form>
<select id="someID_1" name="someID_1" onChange="selectForm1(this.options[this.selectedIndex].value)">
<option>Choose a Page</option>
<option value="1">Page 1</option>
<option value="2">Page 2</option>
<option value="3">Page 3</option>
</select>
</form>

<div id="allForms1">
<form class="hidden">Text of Page 1</form>
<form class="hidden">Text of Page 2</form>
<form class="hidden">Text of Page 3</form>
</div>

CSS

.hidden { display: none; }

信息框.JS

function selectForm1(frm){
/* Select the div containing all the hidden forms */
  var hiddenForms1 = document.getElementById("allForms1");
/* Select every form within the above div and assign it to an array */
  theForm1 = hiddenForms1.getElementsByTagName("form");
/* Set the display for each of the above forms to NONE */
  for(x=0; x<theForm1.length; x++){
    theForm1[x].style.display = "none";
  }
/* If the form selected from the list exists, set its display to BLOCK */
  if (theForm1[frm-1]){
    theForm1[frm-1].style.display = "block";
  }
}
4

1 回答 1

0

好吧,我终于 - 在又一次猜测之后得到了它。这成功了:

<body onload="selectForm1(1)">
于 2013-01-26T17:42:32.697 回答