ITPub博客

首页 > 应用开发 > > 为什么我的if...else 语句, else不能执行?

为什么我的if...else 语句, else不能执行?

作者:lgchen 时间:2019-10-17 13:33:22 0 删除 编辑

<div class="box" id="box"></div>

    <button onclick="myfunction()">按钮</button>

    <script>

    function myfunction() {

    var box = document.getElementById("box");

        if (box.style.backgroundColor="aqua") 

            {

                box.style.backgroundColor="red";

            }

        else {

            box.style.backgroundColor="black";

        }

    }

    </script>

1<br>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1276/viewspace-3140552/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    115
  • 访问量
    1024