简体   繁体   English

未捕获到的Typeerror,损坏的JS

[英]Uncaught Typeerror, Broken JS

I have a menu drop down and a series of filter drop downs, both of which have been working fine up until today. 我有一个菜单下拉菜单和一系列过滤器下拉菜单,直到今天它们都可以正常工作。

After adding a logo, with css, to the menu drop down, when I select a filter it breaks my javascript for the menu and the menu doesn't work at all. 将带有CSS的徽标添加到菜单下拉菜单后,当我选择过滤器时,它会破坏菜单的JavaScript,并且菜单根本无法使用。 I get an Uncaught Typeerror. 我收到未捕获的Typeerror。

The filters use forms and 'get' to sort with the onChange set to re-submit the page with the appropriate 'get' parameters. 过滤器使用表单和“获取”以onChange设置进行排序,以使用适当的“获取”参数重新提交页面。

Here is the menu html 这是菜单html

<button id="burg" onclick="menuChange();" class="hamburger">&#9776;</button>
<button id="xCross" onclick="menuChange();" class="cross">&#735; </button>
<ul id="navList">
            <div class="nav-item">
                <a href="inventory.php">
                    <li>Inventory</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="#">
                    <li>Finance</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="contact.php">
                    <li>Contact Us</li>
                </a>
            </div>
            <div class="nav-item">
                <a href="about.html">
                    <li>About Us</li>
                </a>
            </div>
            <div id="lastNav" class="nav-item">
                <a href="reviews.html">
                    <li>Reviews</li>
                </a>
            </div>

            <div class="" id="navImage">
                <a href="index.html">
                    <li><img src="images/asmOriginalLogo_V4.png" alt="Arizona Specialty Motors"/>
                        <div id="dropDownSocial"> <a href="#"><img class="socialMediaLinks" src="images/fbLogo.png" alt="Facebook"/></a> <a href="#"><img class="socialMediaLinks" src="images/In-Black-128px-TM.png" alt="LinkedIn"/></a> <a href="#"><img class="socialMediaLinks" src="images/instaGlyph.png" alt="Instagram"/></a> <a href="#"><img class="socialMediaLinks" src="images/twitterLogo.png" alt="Twitter" /></a> </div>
                    </li>
                </a>
            </div>
        </ul>
<div id="dropdownFreeze">

Here is my javascript function to open/close the menu. 这是我的JavaScript函数,用于打开/关闭菜单。

function menuChange() {
"use strict";
/****** Variables *****/


// Burger link & image
var burger = document.getElementById("burg");
// Individual drop down elements; home, inventory, etc.
var lines = document.getElementsByClassName("nav-item");
// Overall container; to make dropdown 'un-scrollable'
var mainArea = document.getElementById("dropdownFreeze");
// Cross link & image
var cross = document.getElementById("xCross");
// Background for dropdown & navigation
var navList = document.getElementById("navList");
// Social Media images & buttons
var social = document.getElementById("navImage");


// If menu is open, close it. If closed, open it
if (burger.style.display === 'none') {
    burger.style.display = 'block';
    cross.style.display = 'none';

    navList.style.display = 'none';
    social.style.display = 'none';

    for (var i = 0; i < lines.length; i++) {
        lines[i].style.display = 'none';
    }

    mainArea.style.position = 'relative';


} else {

    burger.style.display = 'none';
    cross.style.display = 'block';

    navList.style.display = 'block';
    social.style.display = 'block';

    for (var j = 0; j < lines.length; j++) {
        lines[j].style.display = 'block';
    }


    mainArea.style.position = 'fixed';


}



}

Here is one of my filters (all of them cause issues now, but didn't before adding the 'navImage' div) 这是我的过滤器之一(所有过滤器现在都引起问题,但是在添加“ navImage” div之前没有发生)

<form name="sortMake" action="inventorySort.php?limit=10&page=1" method="get">
<select name="makeOrder" class="dropButton" onchange=this.form.submit();>
<option value="choose">Make</option>
<?php

$makeQuery = "select distinct make from vehicle order by make asc";
$makeResult = mysqli_query( $con, $makeQuery );
$selectMakeCount = 0;
if ( $makeResult ) {
    while ( $makeRow = mysqli_fetch_array( $makeResult ) ) {


        if ( isset( $_GET[ 'makeOrder' ] ) && $_GET[ 'makeOrder' ] == $makeRow[ 'make' ] ) {
            echo '<option value="' . $makeRow[ 'make' ] . '"selected>' . $makeRow[ 'make' ] . '</option>';

        } else {

            echo '<option value="' . $makeRow[ 'make' ] . '">' . $makeRow[ 'make' ] . '</option>';
                }

            }
        }


?>
</select>

The Uncaught Typeerror points to 未捕获的Typeerror指向

mainArea.style.position = 'relative';

And to

navList.style.display = 'block';

It says that it cannot read property 'style' of null. 它说它无法读取null的属性“样式”。

I'm fairly certain the issue is happening in the filter/get. 我相当确定问题发生在过滤器/获取中。

Wow I feel like a scrub. 哇,我感觉像是磨砂膏。

For whatever reason, my ids for navList and dropDownFreeze got deleted from one of my pages. 无论出于什么原因,我的navList和dropDownFreeze的ID都从我的页面之一中删除了。 After resetting them, it worked perfectly. 重置它们后,它运行完美。

Code: 1 Me: 0 代码:1我:0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM