Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何强制单击按钮;一般数据;?_Javascript_Html - Fatal编程技术网

Javascript 如何强制单击按钮;一般数据;?

Javascript 如何强制单击按钮;一般数据;?,javascript,html,Javascript,Html,以下是我的项目示例: [ 如你所见,我的html代码中有三个按钮。第一个按钮是每次刷新页面或在一段时间后打开项目时是否应该单击它们 <html> <head> </head> <body> <div id="basicData1"> <div id="createMaterialHeader"> <h2><i><b>Create Material</b&g

以下是我的项目示例:

[

如你所见,我的html代码中有三个按钮。第一个按钮是每次刷新页面或在一段时间后打开项目时是否应该单击它们

<html>

<head>
</head>

<body>
  <div id="basicData1">
    <div id="createMaterialHeader">
      <h2><i><b>Create Material</b></i></h2>
      <div id="createMaterialOptions">
        <p>Additional Data</p>
        <p>Org. Level</p>
        <p>Check Screen Data</p>
      </div>
    </div>
    <div class="tab">
      <button class="tablinks" onclick="openTab(event, 'generalData')"><b>General Data</b></button>
      <button class="tablinks" onclick="openTab(event, 'materialData')"><b>Paris</b></button>
      <button class="tablinks" onclick="openTab(event, 'Tokyo')"><b>Tokyo</b></button>
    </div>
    <div id="generalData" class="tabcontent">
      <form>
        <label for="employeeID">Employee ID: </label><br>
        <input type="text" name="employeeID" id="employeeID" readonly><br>
        <hr>
        <label for="requestNo">Request Number: </label><br>
        <input type="text" name="requestNo" id="requestNo" readonly><br>
        <label for="requestedBy">Requested By: </label><br>
        <input type="text" name="requestedBy" id="requestedBy" readonly><br>
        <label for="requestDate">Request Date: </label><br>
        <input type="text" name="requestDate" id="requestDate" readonly><br>
        <hr>
        <label for="eskNumber">(E)SK Number: </label><br>
        <input type="text" name="eskNumber" id="eskNumber" required><br>
        <hr>
        <label for="requestType">Request Type: </label><br>
          <select id="requestTypeSelection">
            <option value="creation">CREATION</option>
            <option value="extension">EXTENSION</option>
            <option value="modification">MODIFICATION</option>
          </select><br>
        <label for="requestSubtype">Request Subtype: </label><br>
          <select id="requestSubtypeSelection">
            <option value="hawaAndZpla">HAWA/ZPLA</option>
            <option value="newBatch">NEW BATCH</option>
            <option value="zplaToHawa">ZPLA>HAWA</option>
            <option value="dien">DIEN</option>
          </select>
      </form>
    </div>

    <div id="materialData" class="tabcontent">
      <form>
        <label for="productNumber">Product Number: </label><br>
        <input type="text" name="productNumber" id="productNumber" required><br>
        <label for="materialName">Material Name: </label><br>
        <input type="text" name="materialName" id="materialName" required><br>
      </form>
    </div>

    <div id="Tokyo" class="tabcontent">
      <h3>Tokyo</h3>
      <p>Tokyo is the capital of Japan.</p>
    </div>
  </div>
</body>
</html>

创造材料
附加数据

组织级

检查屏幕数据

一般数据 巴黎 东京 员工ID:


请求编号:

请求人:

请求日期:


(E) SK编号:


请求类型:
创造 延伸 修改
请求子类型:
夏威夷/解放军 新批次 ZPLA>哈瓦 迪恩 产品编号:

物料名称:

东京 东京是日本的首都

和JS代码,其中包括执行此操作所需的window.onload函数:

document.getElementById("requestTypeSelection").selectedIndex = -1;
document.getElementById("requestSubtypeSelection").selectedIndex = -1;

function openTab(evt, tabName) {
  // Declare all variables
  var i, tabcontent, tablinks;

  // Get all elements with class="tabcontent" and hide them
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }

  // Get all elements with class="tablinks" and remove the class "active"
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }

  // Show the current tab, and add an "active" class to the button that opened the tab
  document.getElementById(tabName).style.display = "block";
  evt.currentTarget.className += " active";
}

window.onload = function() {
  document.getElementById("generalData").onclick = document.getElementById("generalData").style.display = "block";
}
document.getElementById(“requestTypeSelection”).selectedIndex=-1;
document.getElementById(“RequestSubjectSelection”).selectedIndex=-1;
函数openTab(evt,tabName){
//声明所有变量
var i,tabcontent,tablinks;
//使用class=“tabcontent”获取所有元素并隐藏它们
tabcontent=document.getElementsByClassName(“tabcontent”);
对于(i=0;i

其主要思想是在刷新页面后始终单击“常规数据”按钮(选择E等)。您能告诉我如何在JS代码中更正吗?

看,这并不能解决您的问题:

window.onload = () => {
    document.getElementById("generalData").style.display = "block"
.
.
.
}

你不必模拟按钮的点击,你只需触发它的动作

ok我在上面的代码中添加了event.currentTarget.className+=“active”;现在它可以工作了:)太好了,我很高兴。别忘了计算并关闭这个问题,见:)请接受最好的答案✔️