亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調用 getElementsByClassName 函數后,某些圖像沒有變化

調用 getElementsByClassName 函數后,某些圖像沒有變化

GCT1015 2023-10-24 15:12:06
在我的應用程序中,打開深色模式功能后,我希望將一些圖像更改為其他圖像。但當圖像由兩張圖片組成時,這種情況就不會發生,然后此后的其余圖像也不會發生變化,這是清楚描述問題的圖像。這是 PHP 和 javascript 代碼:   <?php } else if ($rating_avg > 4.75 && $rating_avg < 6) { ?>        <form class="star-form" action="star_frame.php?post_id=<?= $post_id ?>" method="POST">            <div class='stars_avg_div' align='center'>                <i class='star1' id='star1' style='width:20px; height:20px; '><img class='star1img' src='starou.png' style='width:20px; height:20px;background-color:gold; '></i>                <i class='star2' id='star2' style='width:20px; height:20px; '><img class='star2img' src='starou.png' style='width:20px; height:20px;background-color:gold;'></i>                <i class='star3' id='star3' style='width:20px; height:20px; '><img class='star3img' src='starou.png' style='width:20px; height:20px;background-color:gold;'></i>                <i class='star4' id='star4' style='width:20px; height:20px; '><img class='star4img' src='starou.png' style='width:20px; height:20px;background-color:gold;'></i>                <i class='star5' id='star5' style='width:20px; height:20px; '><img class='star5img' src='starou.png' style='width:20px; height:20px;background-color:gold;'></i>            </div>        </form>    <?php } ?>    function darkmode() {            $('*').addClass('dark');            $('avg_iframe').addClass('dark');        }頁面加載時,控制臺面板顯示錯誤“TypeError:document.getElementsByClassName(...)[0] 未定義 star_avg_frame.php:88:22(參考最后幾行代碼)”我也嘗試過getElementsByIdName,getElementsByClassName但不是這樣。您知道為什么會發生圖像上顯示的情況嗎?我必須補充一點,如果沒有“半星”,一切都會很好。在此先感謝您的幫助!
查看完整描述

1 回答

?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

您可以使用querySelector(".star1img")代替getElementsByClassName,并獲得第一個元素class="star1img"

document.getElementById("half_star_1")[0].src = "starou_half_1_dark.png"沒有任何意義,因為getElementById你得到的是 1 個元素,而不是數組。所以你不需要在它后面使用[0]。另外,頁面上沒有具有此 id 的元素


查看完整回答
反對 回復 2023-10-24
  • 1 回答
  • 0 關注
  • 127 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號