JavaScript选项卡将home设为默认值

时间:2018-03-22 04:20:31

标签: javascript html

如何在加载时将主页选项卡设为默认值?



<ul class="tab" onload="openAction(event, 'All')">
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'home')">Home</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'generate')">Generate QR</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'report')">Reports</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'condemn')">Condemn Equipments</a></li>
</ul>

and upon clicking a tab

<div id="home" class="tabcontent" selected="All" background="images/bodybg.jpg">
  My Home

</div>
<div id="generate" class="tabcontent" selected="All" background="images/bodybg.jpg">
  Generate

</div>
<div id="report" class="tabcontent" selected="All" background="images/bodybg.jpg">
  My Reports

</div>
<div id="condemn" class="tabcontent" selected="All" background="images/bodybg.jpg">
  Condemn Equipments

</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

<ul class="tab">
  <li><a id="hometag" href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'home')">Home</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'generate')">Generate QR</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'report')">Reports</a></li>
  <li><a href="javascript:void(0)" class="tablinks" onclick="openAction(event, 'condemn')">Condemn Equipments</a></li>
</ul>


<div id="home" class="tabcontent" selected="All" background="images/bodybg.jpg">
  My Home

</div>
<div id="generate" class="tabcontent" selected="All" background="images/bodybg.jpg">
  Generate

</div>
<div id="report" class="tabcontent" selected="All" background="images/bodybg.jpg">
  My Reports

</div>
<div id="condemn" class="tabcontent" selected="All" background="images/bodybg.jpg">
  Condemn Equipments

</div>

<script>
(function() {
document.getElementById("hometag").click();
})();
</script>