Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.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的情况下使用PHP填充页面上的HTML表?_Javascript_Php_Html_Sql_Html Table - Fatal编程技术网

如何在不破坏JavaScript的情况下使用PHP填充页面上的HTML表?

如何在不破坏JavaScript的情况下使用PHP填充页面上的HTML表?,javascript,php,html,sql,html-table,Javascript,Php,Html,Sql,Html Table,我正在尝试使用HTML、CSS、JS和PHP制作一个简单的仪表板 我的页面上有一些JavaScript来处理大部分转换和移动div。我的主页还有一个HTML表,它将从数据库中提取一些行,但是当我使用PHP连接到SQL Server并返回这些行时,我的JavaScript停止工作。具体来说,当我将我的页面从.html扩展名转换为.php扩展名时,JavaScript将不再运行,并且在控制台中出现错误。从数据库中提取数据以缓解此问题的最佳方法是什么。示例代码如下: JS与我的表无关,但是每当我在这个

我正在尝试使用HTML、CSS、JS和PHP制作一个简单的仪表板


我的页面上有一些JavaScript来处理大部分转换和移动div。我的主页还有一个HTML表,它将从数据库中提取一些行,但是当我使用PHP连接到SQL Server并返回这些行时,我的JavaScript停止工作。具体来说,当我将我的页面从.html扩展名转换为.php扩展名时,JavaScript将不再运行,并且在控制台中出现错误。从数据库中提取数据以缓解此问题的最佳方法是什么。示例代码如下:

JS与我的表无关,但是每当我在这个页面上开始使用php时,它就会停止运行。JS用于切换当前显示的div,以模拟切换页面

HTML-这是我试图从SQL数据库填充的表元素

  <body>
    <div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
      <header class="demo-header mdl-layout__header mdl-color--white mdl-color-text--grey-600">
        <div class="mdl-layout__header-row">
          <span><img src=".\images\comp_now.png" width="50%" height="50%"></span>
          <span class="mdl-layout-title">Dashboard</span>
          <div class="mdl-layout-spacer"></div>
          <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable">
            <label class="mdl-button mdl-js-button mdl-button--icon" for="search">
              <i class="material-icons">search</i>
            </label>
            <div class="mdl-textfield__expandable-holder">
              <input class="mdl-textfield__input" type="text" id="search">
              <label class="mdl-textfield__label" for="search">Enter your query...</label>
            </div>
          </div>
        </div>
      </header>
      <!--Side Panel-->
      <div class="demo-drawer mdl-layout__drawer mdl-color--black mdl-color-text--blue-grey-50">
        <header class="demo-drawer-header">
          <img src="images/user.jpg" class="demo-avatar">
          <div class="demo-avatar-dropdown">
            <span>hello@example.com</span>
            <div class="mdl-layout-spacer"></div>
            <button id="accbtn" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
              <i class="material-icons" role="presentation">arrow_drop_down</i>
              <span class="visuallyhidden">Accounts</span>
            </button>
            <ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="accbtn">
              <li class="mdl-menu__item">
                <!-- Accent-colored raised button with ripple -->
                <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
                  Sign Out
                </button>
              </li>
            </ul>
          </div>
        </header>
        <!--Page Navigation-->
        <nav class="demo-navigation mdl-navigation mdl-color--white mdl-color-text--blue-grey-50">
          <a class="mdl-navigation__link" onclick="switchMain('PO_LIST')"><i class="mdl-color-text--blue-A400 material-icons" role="presentation">list</i>PO List</a>
          <a class="mdl-navigation__link" onclick="switchMain('PO_ITEMS')"><i class="mdl-color-text--blue-A400 material-icons" role="presentation">shopping_cart</i>PO Items</a>
          <a class="mdl-navigation__link" onclick="switchMain('VENDORS')"><i class="mdl-color-text--blue-A400 material-icons" role="presentation">storefront</i>Vendors</a>
          <a class="mdl-navigation__link" onclick="switchMain('REPORTS')"><i class="mdl-color-text--blue-A400 material-icons" role="presentation">bar_chart</i>Reports</a>
          <div class="mdl-layout-spacer"></div>
        </nav>
      </div>
      <main class="mdl-layout__content mdl-color--grey-100" style="padding-top: 20px; padding-left: 20px;">
      <div class="main" id="PO_LIST">
        <div style="padding-bottom: 10px;">
          <!-- Accent-colored raised button with ripple -->
          <button id="New_PO" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent trigger" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">add</i>
            New Purchase Order
          </button>
        </div>
        <div>
          <table class="mdl-data-table mdl-js-data-table" style="overflow-y: auto">
            <thead class="mdl-color--amber-700">
              <tr>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Edit</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Status</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">PO Number</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">PO Date</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Name</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Vendor</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Received</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Shipping Cost</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Taxes</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">PO Total</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Requestor</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Budget</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <?php 
                  include 'po_list_table.php'; 
                  pullDBRows();
                ?>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="main" id="PO_ITEMS" style="display: none; overflow-x: auto; overflow-y: auto;">
        <div style="padding-bottom: 30px;">
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent new_item_trigger" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">add</i>
            New Item
          </button>
        </div>
        <div>
          <table class="mdl-data-table mdl-js-data-table">
            <thead class="mdl-color--amber-700">
              <tr>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Edit</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Item ID</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Name</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Description</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Brand</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Vendor</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Quantity</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Unit Price</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Line Price</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Category</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class="mdl-data-table__cell--non-numeric"><i class="mdl-color-text--black material-icons">edit</i></td>
                <td class="mdl-data-table__cell--non-numeric">POI-000001</td>
                <td class="mdl-data-table__cell--non-numeric">Keyboard & Mouse Combo</td>
                <td class="mdl-data-table__cell--non-numeric">Logitech MK545</td>
                <td class="mdl-data-table__cell--non-numeric">Logitech</td>
                <td class="mdl-data-table__cell--non-numeric">Best Buy</td>
                <td class="mdl-data-table__cell--non-numeric">20</td>
                <td class="mdl-data-table__cell--non-numeric">$29.99</td>
                <td class="mdl-data-table__cell--non-numeric">$599.80</td>
                <td class="mdl-data-table__cell--non-numeric">Peripherals</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="main" id="VENDORS" style="display: none; overflow-x: auto; overflow-y: auto;">
        <div style="padding-bottom: 30px;">
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent trigger3" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">add</i>
            New Vendor
          </button>
        </div>
        <div>
          <table class="mdl-data-table mdl-js-data-table">
            <thead class="mdl-color--amber-700">
              <tr>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Edit</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Vendor ID</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Name</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Description</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Street Address 1</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Street Address 2</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">City</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">State</th>
                <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Zip</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class="mdl-data-table__cell--non-numeric"><i class="mdl-color-text--black material-icons">edit</i></td>
                <td class="mdl-data-table__cell--non-numeric">VEN-000001</td>
                <td class="mdl-data-table__cell--non-numeric">Softchoice</td>
                <td class="mdl-data-table__cell--non-numeric">Computer Company</td>
                <td class="mdl-data-table__cell--non-numeric"></td>
                <td class="mdl-data-table__cell--non-numeric"></td>
                <td class="mdl-data-table__cell--non-numeric"></td>
                <td class="mdl-data-table__cell--non-numeric"></td>
                <td class="mdl-data-table__cell--non-numeric"></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="main" id="REPORTS" style="display: none; overflow-x: auto; overflow-y: auto;">
        <div style="padding-bottom: 30px;">
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            PO Totals
          </button>
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            Total by Vendor
          </button>
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            Total by Category
          </button>
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            Total by Budget
          </button>
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            2020 PO Total
          </button>
          <!-- Accent-colored raised button with ripple -->
          <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-right: 20px;"><i class="mdl-color-text--white material-icons">bar_chart</i>
            2021 PO Total
          </button>
        </div>
        <div>
          <iframe width="100%" height="750px" src="https://app.powerbi.com/reportEmbed?reportId=9dec551d-7f49-4b7b-9504-72318e287b04&autoAuth=true&ctid=4c52dc5e-4ed5-4645-a209-ed3c32f5ec3c&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6Ly93YWJpLXVzLWVhc3QyLXJlZGlyZWN0LmFuYWx5c2lzLndpbmRvd3MubmV0LyJ9" frameborder="0" allowFullScreen="true"></iframe>
        </div>
      </div>
      <!--New Purchase Order Modal-->
      <div class="modal">
        <div class="modal-content">
            <span class="close-button">&times;</span>
            <h5>New Purchase Order</h5><br>
            <div style="display: inline-block;">
              <form action="#">
                <div class="mdl-grid">
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
                    <input class="mdl-textfield__input" type="text" id="PO_Title">
                    <label class="mdl-textfield__label" for="PO_Title">PO Name</label>
                  </div>
                </div>
                <div class="mdl-grid">
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                    <input class="mdl-textfield__input" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')" id="PO_Date">
                    <label class="mdl-textfield__label" for="PO_Date">PO Date</label>
                  </div>
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                    <input class="mdl-textfield__input" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')" id="Order_Date">
                    <label class="mdl-textfield__label" for="Order_Date">Order Date</label>
                  </div>
                </div>
                <div class="mdl-grid">
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
                    <input class="mdl-textfield__input" type="text" rows= "3" id="Description">
                    <label class="mdl-textfield__label" for="Description">Description</label>
                  </div>
                </div>
                <div class="mdl-grid">
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                    <input class="mdl-textfield__input" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')" id="Ship_Date">
                    <label class="mdl-textfield__label" for="Order_Date">Ship Date</label>
                  </div>
                  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                    <input class="mdl-textfield__input" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')" id="Date_Received">
                    <label class="mdl-textfield__label" for="Date_Received">Date Received</label>
                  </div>
                </div>
                <div class="mdl-grid">
                  <h6 class="mdl-cell mdl-cell--12-col">Shipping Cost: $79.99</h6>
                  <h6 class="mdl-cell mdl-cell--12-col">Taxes: $247.89</h6>
                  <h5 class="mdl-cell mdl-cell--12-col">PO Total: $25,487.99</h5>
                  <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="float: right; margin-left: 80%;">
                    Save Order
                  </button>
              </div>
              </form>
            </div>
            <div class="mdl-grid" style="float: right;">
              <div class="mdl-cell mdl-cell--12-col">
                <h6 style="display: inline-block;">PO Items</h6>
                <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="float: right;"><i class="mdl-color-text--white material-icons">add</i>
                  New PO Item
                </button>
                <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="float: right; margin-right: 5%;"><i class="mdl-color-text--white material-icons">add</i>
                  From Inventory
                </button>
                <div style= "overflow-x: auto; overflow-y: auto;">
                  <table class="mdl-data-table mdl-js-data-table">
                    <thead class="mdl-color--amber-700">
                      <tr>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Name</th>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Quantity</th>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Unit Price</th>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Line Price</th>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Category</th>
                        <th class="mdl-data-table__cell--non-numeric mdl-color-text--white">Remove</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td class="mdl-data-table__cell--non-numeric">Keyboard & Mouse Combo</td>
                        <td class="mdl-data-table__cell--non-numeric">20</td>
                        <td class="mdl-data-table__cell--non-numeric">$29.99</td>
                        <td class="mdl-data-table__cell--non-numeric">$599.80</td>
                        <td class="mdl-data-table__cell--non-numeric">Peripherals</td>
                        <td class="mdl-data-table__cell--non-numeric"><i class="mdl-color-text--gray material-icons">delete</i></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
        </div>
      </div>
      <!--New PO Item Modal-->
      <div class="modal2">
          <div class="modal-content2">
            <span class="close-button2">&times;</span>
            <h5>New Inventory Item</h5>
            <form action="#">
              <div class="mdl-grid">
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
                  <input class="mdl-textfield__input" type="text" id="inv_item_name">
                  <label class="mdl-textfield__label" for="inv_item_name">Item Name</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="inv_brand">
                  <label class="mdl-textfield__label" for="inv_brand">Manufacturer</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="inv_category">
                  <label class="mdl-textfield__label" for="inv_category">Category</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="inv_vendor">
                  <label class="mdl-textfield__label" for="inv_vendor">Vendor</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="inv_quantity">
                  <label class="mdl-textfield__label" for="inv_quantity">Quantity</label>
                  <span class="mdl-textfield__error">Input is not a number!</span>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="inv_unit_price">
                  <label class="mdl-textfield__label" for="inv_unit_price">Unit Price</label>
                </div>
              </div>
              <div class="mdl-grid">
                <!-- Accent-colored raised button with ripple -->
                <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-left: 65%;">
                  Save Item
                </button>
              </div>
            </form>
          </div>
      </div>
      <!--New Vendor Modal-->
      <div class="modal3">
        <div class="modal-content3">
            <span class="close-button3">&times;</span>
            <h5>New Vendor</h5>
            <form action="#">
              <div class="mdl-grid">
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
                  <input class="mdl-textfield__input" type="text" id="ven_name">
                  <label class="mdl-textfield__label" for="ven_name">Vendor Name</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="ven_addr1">
                  <label class="mdl-textfield__label" for="ven_addr2">Street Address 1</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="ven_addr2">
                  <label class="mdl-textfield__label" for="ven_addr2">Street Address 2</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="ven_city">
                  <label class="mdl-textfield__label" for="ven_city">City</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" id="ven_state">
                  <label class="mdl-textfield__label" for="ven_state">State</label>
                </div>
                <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--6-col">
                  <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="ven_zip">
                  <label class="mdl-textfield__label" for="ven-zip">Zip</label>
                  <span class="mdl-textfield__error">Input is not a number!</span>
                </div>
              </div>
              <div class="mdl-grid">
                <!-- Accent-colored raised button with ripple -->
                <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="margin-left: 65%;">
                  Save Vendor
                </button>
              </div>
            </form>
        </div>
      </div>
    </main>
    </div>
  </body>
  <script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
    <!--New Purchase Order JS-->
    <script>
      var modal = document.querySelector(".modal");
      var trigger = document.querySelector(".trigger");
      var closeButton = document.querySelector(".close-button");

      function toggleModal() {
          modal.classList.toggle("show-modal");
      }

      function windowOnClick(event) {
          if (event.target === modal) {
              toggleModal();
          }
      }

      trigger.addEventListener("click", toggleModal);
      closeButton.addEventListener("click", toggleModal);
      //window.addEventListener("click", windowOnClick);
    </script>
    <!--New Inventory Item JS-->
    <script>
      var modal2 = document.querySelector(".modal2");
      var trigger2 = document.querySelector(".new_item_trigger");
      var closeButton2 = document.querySelector(".close-button2");

      function toggleModal() {
          modal2.classList.toggle("show-modal2");
      }

      function windowOnClick(event) {
          if (event.target === modal2) {
              toggleModal();
          }
      }

      trigger2.addEventListener("click", toggleModal);
      closeButton2.addEventListener("click", toggleModal);
      //window.addEventListener("click", windowOnClick);
    </script>
    <!--New Vendor JS-->
    <script>
      var modal3 = document.querySelector(".modal3");
      var trigger3 = document.querySelector(".trigger3");
      var closeButton3 = document.querySelector(".close-button3");

      function toggleModal() {
          modal3.classList.toggle("show-modal3");
      }

      function windowOnClick(event) {
          if (event.target === modal3) {
              toggleModal();
          }
      }

      trigger3.addEventListener("click", toggleModal);
      closeButton3.addEventListener("click", toggleModal);
      //window.addEventListener("click", windowOnClick);
    </script>
</html>

这就是我在控制台中遇到的错误:当我单击由JavaScript管理的页面导航链接时,就会出现这种错误。
发现问题出在我的PHP上。我从数据库中提取的日期时间格式导致正确加载PHP出现问题。

仅更改文件扩展名不应导致JS错误。你确定你只改变了这些吗?您会遇到哪些具体错误?您显示的JS似乎与您的表没有任何关系,尽管您没有向我们显示JS正在处理的任何HTML元素(例如,“PO_LIST”在哪里)。你知道PHP是100%的“服务器端”,JS是100%的“浏览器端”:从来没有任何直接的“冲突”。另外:PHP文件的正确文件名应该是“.PHP”。话虽如此,在浏览器中呈现为HTML的PHP的行为应该与等效的static.HTML页面相同。最后:请更新您的帖子并复制/粘贴“控制台中的错误”“我在控制台中得到错误”-请分享!谢谢假设
document.getElementById('PO_ITEMS').style.display
为第3行,则表示页面中没有ID为
PO_ITEMS
的元素。你没有在你的问题中显示一个,但是我很确定你没有向我们显示整个HTML。无论如何,这是一个非常基本的错误,很难看出更改文件扩展名是如何导致的。在JavaScript被执行的那一刻,HTML中根本不存在这个元素。这不会解决问题,但我会稍微重构一下您的代码。应避免使用内联javascript,而应指定事件侦听器。正确使用链接进行内部链接,然后使用javascript切换类,让css处理隐藏或显示。请参阅:关于避免什么或问题到底是什么的具体细节将使您的答案在将来对其他人更有用
<?php
    function pullDBRows(){
        $serverName = "*****";

        $connectionInfo = array ("Database"=>"*****", "UID"=>"*****", "PWD"=>"*****");
        $conn = sqlsrv_connect($serverName, $connectionInfo);
    
        if( $conn ) {
            "Connection established.<br />";
        } else{
            "Connection could not be established.<br />";
            die( print_r( sqlsrv_errors(), true));
        }
    
        $tquery = "Select * from Purchase_Orders";
        $stmt = sqlsrv_query( $conn, $tquery );
        if( $stmt === false) {
            die( print_r( sqlsrv_errors(), true) );
        }
        while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
            echo "<td><i class='mdl-color-text--black material-icons'>edit</i></td>";
            echo "<td>".$row['Status']."</td>";
            echo "<td>".$row['PO_Number']."</td>";
            echo "<td>".$row['PO_Date']->format('m/d/y')."</td>";
            echo "<td>".$row['Title']."</td>";
            echo "<td>".$row['Vendor']."</td>";
            echo "<td>".$row['Date_Received']->format('m/d/y')."</td>";
            echo "<td>".$row['Shipping_Price']."</td>";
            echo "<td>".$row['Sales_Tax']."</td>";
            echo "<td>".$row['Total_Amount']."</td>";
            echo "<td>".$row['Requester']."</td>";
            echo "<td>".$row['Budget']."</td>";
            echo "</tr>";
        } 
    }
?>
function switchMain(screen) {
    document.getElementById('PO_LIST').style.display = 'none';
    document.getElementById('PO_ITEMS').style.display = 'none';
    document.getElementById('VENDORS').style.display = 'none';
    document.getElementById('REPORTS').style.display = 'none';
    document.getElementById(screen).style.display = 'block';
  }