Javascript php:113未捕获类型错误:无法设置属性';显示';未定义-读取体的类型

Javascript php:113未捕获类型错误:无法设置属性';显示';未定义-读取体的类型,javascript,php,html,Javascript,Php,Html,我看了很多已经回答过的问题,但没有一个是有效的。因此,这就是我现在穿上这件衣服的原因。我试图在用户单击月份时打印数据。我以前让它工作过,但它只会打印特定月份的一条数据。但是,每个月都有多个数据块,因此我希望所有数据都显示出来 不断出现的错误是 rallies.php:113 Uncaught TypeError: Cannot set property 'display' of undefined 我的HTML: <div class="calander-container"&g

我看了很多已经回答过的问题,但没有一个是有效的。因此,这就是我现在穿上这件衣服的原因。我试图在用户单击月份时打印数据。我以前让它工作过,但它只会打印特定月份的一条数据。但是,每个月都有多个数据块,因此我希望所有数据都显示出来

不断出现的错误是

rallies.php:113 Uncaught TypeError: Cannot set property 'display' of undefined
我的HTML:

    <div class="calander-container">
        <div class="months">
            <p class="months-text">January</p>
        </div>
        <div class="months">
            <p class="months-text">February</p>
        </div>
        <div class="months">
            <p class="months-text">March</p>
        </div>
        <div class="months">
            <p class="months-text">April</p>
        </div>
        <div class="months">
            <p class="months-text">May</p>
        </div>
        <div class="months">
            <p class="months-text">June</p>
        </div>
        <div class="months">
            <p class="months-text">July</p>
        </div>
        <div class="months">
            <p class="months-text">August</p>
        </div>
        <div class="months">
            <p class="months-text">September</p>
        </div>
        <div class="months">
            <p class="months-text">October</p>
        </div>
        <div class="months">
            <p class="months-text">November</p>
        </div>
        <div class="months">
            <p class="months-text">December</p>
        </div>
    </div>

el.style
未定义,因为
document.getElementsByClassName
返回HTMLCollection(数组)

您将有更多机会访问,例如
el[0]条件是类实际存在于DOM中

if($row['month'] === 'January'){

                echo "<div class='rallyPrintJan'>";
                echo "<h2>" . $row['rallyVenue'] . " in " . $row['month'] . " " . $row['year'] . "</h2>";
                echo "<h4>Event: ". $row['rallyEvent'] . " </h4>";
                echo "<h3>Your Marshall(s): " . $row['rallyMarsh'] . "</h3>";
                echo "<h4>When? ". $row['rallyDate'] . " </h4>";
                echo "<p>" . $row['rallyDesc'] . "</p>";
                echo "<p>How much? ". $row['rallyCost'] . " </p>";
                echo "<p>How long? ". $row['rallyNights'] . " Nights</p>";
                echo "<p>Pitch Limit? ". $row['pitchLimit'] . "</p>";
                echo "<p>Phone Number: 0". $row['phoneNo'] . " </p>";
                echo "<p>Email: <a href='mailto:". $row['email'] . "'> ". $row['email'] ."</a></p>";
                echo "<p>Please make sure you to contact ". $row['rallyMarsh'] . " for more information.</p>";
                if(isset($_SESSION['loggedin'])){
                    echo "<a href='' id='". $row['rallyId'] . "' class='trash'>Delete</a>";
                }
                echo "</div><br>";
                 }
document.querySelector('.months').addEventListener('click', (e) => {

    const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    var monthName;

    months.forEach(month => {
    const el = document.getElementsByClassName("rallyPrint" + month);

    if (monthName === month) {
            el.style.display = "block"; // Show current month
    } else {
            el.style.display = "none"; // Not the current month, hide
    }

  });

});