第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何修復(fù)“未捕獲的類型錯誤:無法讀取 null 的屬性‘樣式’”的錯誤

如何修復(fù)“未捕獲的類型錯誤:無法讀取 null 的屬性‘樣式’”的錯誤

德瑪西亞99 2022-11-03 15:11:22
我是 web 開發(fā)的新手,實際上我對 js 幾乎一無所知。我正在嘗試“禁用” 3 個按鈕,然后單擊它們 5 秒鐘。我的 ID 是正確的,但它只給我這個錯誤stop和restart按鈕/i。它適用于play.Error that I got -> Uncaught TypeError: Cannot read property 'style' of null    at actionButtonfuction (Website:145)    at HTMLButtonElement.onclick (Website:179)在單個函數(shù)中可以設(shè)置多少個項目的樣式是否有任何限制?<script>  function actionButtonfuction() {    document.getElementById("actionButton").disabled = true;    document.getElementById("play").style.color = "#808080";    document.getElementById("stop").style.color = "#808080";    document.getElementById("restart").style.color = "#808080";    setTimeout(function() {      document.getElementById("actionButton").disabled = false;      document.getElementById("play").style.color = "#16a72d";      document.getElementById("stop").style.color = "#db3224";      document.getElementById("restart").style.color = "#1b6ec2"    }, 5000);    //console.log("button clicked");  }</script><button class="console_button" onclick="actionButtonfuction()" id="actionButton" asp-action="">  <i id="stop" class="fa fa-stop"></i></button><button class="console_button" onclick="actionButtonfuction()" id="actionButton" asp-action="">   <i id="play" class="fa fa-play"></i></button><button class="console_button" onclick="actionButtonfuction()" id="actionButton" asp-action="">   <i id="restart" class="fa fa-refresh"></i></button>
查看完整描述

3 回答

?
翻翻過去那場雪

TA貢獻(xiàn)2065條經(jīng)驗 獲得超14個贊

對于多個元素,您應(yīng)該使用一個。 id 屬性在頁面中必須是唯一的,并且被設(shè)計為唯一的 id 以引用一個 DOM 對象。您還需要遍歷所有要操作的 DOM 對象。

我已將 actionButton 添加到每個按鈕的類中,并使用getElementsByClassName來獲取所有按鈕,并使用for-of 循環(huán)對它們進(jìn)行迭代。

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


<script>

  function actionButtonfuction() {

    for(const el of document.getElementsByClassName("actionButton"))

      el.disabled = true;

    document.getElementById("play").style.color = "#808080";

    document.getElementById("stop").style.color = "#808080";

    document.getElementById("restart").style.color = "#808080";

    setTimeout(function() {

      for(const el of document.getElementsByClassName("actionButton"))

        el.disabled = false;

      document.getElementById("play").style.color = "#16a72d";

      document.getElementById("stop").style.color = "#db3224";

      document.getElementById("restart").style.color = "#1b6ec2"

    }, 5000);

    //console.log("button clicked");

  }

</script>


<button class="console_button actionButton" onclick="actionButtonfuction()" asp-action="">

  <i id="stop" class="fa fa-stop"></i>

</button>


<button class="console_button actionButton" onclick="actionButtonfuction()" asp-action="">

   <i id="play" class="fa fa-play"></i>

</button>


<button class="console_button actionButton" onclick="actionButtonfuction()" asp-action="">

   <i id="restart" class="fa fa-refresh"></i>

</button>


查看完整回答
反對 回復(fù) 2022-11-03
?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊

首先,所有按鈕都具有相同的 ID,這是不允許的,因為 ID 應(yīng)該是唯一的。play其次,在您的代碼中,沒有 idstop或restart. 我認(rèn)為要使您的代碼正常工作,它應(yīng)該是這樣的:


<script>

    function actionButtonfuction() {

        var btns = document.getElementsByClassName('actionButton');

        for(var i = 0; i < btns.length; i++) {

           btns[i].setAttribute('disabled','true');

        }

        document.getElementById("play").style.color = "#808080";

        document.getElementById("stop").style.color = "#808080";

        document.getElementById("restart").style.color = "#808080";

        setTimeout(() => {

            var btns = document.getElementsByClassName('actionButton');

            for(var i = 0; i < btns.length; i++) {

               btns[i].setAttribute('disabled','true');

            }

            document.getElementById("play").style.color = "#16a72d";

            document.getElementById("stop").style.color = "#db3224";

            document.getElementById("restart").style.color = "#1b6ec2"

        }, 5000);

    }

</script>

對于 HTML:


<button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="stop" asp-action="">

   <i class="fa fa-stop"></i>

</button>


<button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="play" asp-action="">

   <i class="fa fa-play"></i>

</button>


<button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="restart" asp-action="">

   <i class="fa fa-refresh"></i>

</button>

所以完全像這樣:


<!DOCTYPE HTML>

<html>

  <head>

    <title>Buttons</title>

  </head>

  <body>

  <button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="stop" asp-action="">

   <i class="fa fa-stop"></i>

</button>


<button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="play" asp-action="">

   <i class="fa fa-play"></i>

</button>


<button class="console_button" class="actionButton" onclick="actionButtonfuction()" id="restart" asp-action="">

   <i class="fa fa-refresh"></i>

</button>

  <script>

    function actionButtonfuction() {

        var btns = document.getElementsByClassName('actionButton');

        for(var i = 0; i < btns.length; i++) {

           btns[i].setAttribute('disabled','true');

        }

        document.getElementById("play").style.color = "#808080";

        document.getElementById("stop").style.color = "#808080";

        document.getElementById("restart").style.color = "#808080";

        setTimeout(() => {

            var btns = document.getElementsByClassName('actionButton');

            for(var i = 0; i < btns.length; i++) {

               btns[i].setAttribute('disabled','false');

            }

            document.getElementById("play").style.color = "#16a72d";

            document.getElementById("stop").style.color = "#db3224";

            document.getElementById("restart").style.color = "#1b6ec2"

        }, 5000);

    }

</script>

  </body>

</html>

請注意我沒有測試過代碼。


查看完整回答
反對 回復(fù) 2022-11-03
?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗 獲得超11個贊

我找到了問題的實際答案


<script>

function actionButtonfuction() {

    for (const el of document.getElementsByClassName("actionButton"))

        el.disabled = true;

    if (typeof (document.getElementById("play")) != 'undefined' && document.getElementById("play") != null) {

        document.getElementById("play").style.color = "#808080";

    } 

    if (typeof (document.getElementById("stop")) != 'undefined' && document.getElementById("stop") != null) {

        document.getElementById("stop").style.color = "#808080";

    }

    if (typeof (document.getElementById("restart")) != 'undefined' && document.getElementById("restart") != null) {

        document.getElementById("restart").style.color = "#808080";

    }

    setTimeout(function () {

        for (const el of document.getElementsByClassName("actionButton"))

            el.disabled = false;

        if (typeof (document.getElementById("play")) != 'undefined' && document.getElementById("play") != null) {

            document.getElementById("play").style.color = "#16a72d";

        }

        if (typeof (document.getElementById("stop")) != 'undefined' && document.getElementById("stop") != null) {

            document.getElementById("stop").style.color = "#db3224";

        }

        if (typeof (document.getElementById("restart")) != 'undefined' && document.getElementById("restart") != null) {

            document.getElementById("restart").style.color = "#1b6ec2"

        }

    }, 5000);

    //console.log("button clicked");

}


查看完整回答
反對 回復(fù) 2022-11-03
  • 3 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號