<table id="selectsupp">
  <tr>
    <td>
      <select id="category">
        <option value="display" readonly="true">-Shop By Category-</option>
        <option value="all">All</option>
        <option value="preworkout">Pre Workout</option>
        <option value="protein">Protein</option>
        <option value="mass">Mass Gainer</option>
        <option value="bcaa">BCAA</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <select id="company">
        <option value="display" readonly="true">-Shop By Company-</option>
        <option value="all">All</option>
        <option value="on">Optimum Nutrition</option>
        <option value="mts">MTS</option>
        <option value="mutant">Mutant Nutrition</option>
        <option value="allmax">All Max</option>
      </select>
    </td>
    <td>
      <input type="submit" id="submit" name="search" value="Search" onclick="find()"/>
    </td>
  </tr>
</table>

<script>
  function find(){
    var category = document.getElementById('category');
    var valueOfCategory = category.options[category.selectedIndex].value;
    var company = document.getElementById('company');
    var valueOfCompany = company.options[company.selectedIndex].value;

    if (valueOfCategory === "all" && valueOfCompany === "all") {
      alert "hello";
      document.getElementsByTagName("select")[0].style.visibility = "hidden";
      document.getElementsByTagName("select")[1].style.visibility = "hidden";
      //display all suggested items
   }


各位程序员,您好:)我在设置标签的可见性时遇到了一些麻烦。当我提交时,我试图摆脱2个选择选项和按钮,但由于某种原因,它设置.style.visibility =“ hidden”无效。有什么建议么?

最佳答案

有两个问题

alert "hello";


应该

alert("hello");


并且在功能末尾缺少}。而且我也没有看到script标记也关闭。

关于javascript - 更改点击元素的可见性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25130894/

10-09 08:54