简体   繁体   English

javascript 未在 html 代码中启用,pycharm IDE

[英]javascript is not enabling within html code, pycharm IDE

The following is the code : when I click on R or G or B buttons, colors should be changed, but not happening as expected, what was the wrong?以下是代码:当我点击 R 或 G 或 B 按钮时,颜色应该改变,但没有按预期发生,出了什么问题?

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>BackGround</title> </head> <body> <button id="red"> R </button> <button id="blue"> B </button> <button id="green"> G </button> <script> let body = document.querySelector('body'); document.querySelector('#red').oncliclk = function() { body.style.backgroundColor = 'red'; }; document.querySelector('#blue').oncliclk = function() { body.style.backgroundColor = 'blue'; }; document.querySelector('#green').oncliclk = function() { body.style.backgroundColor = 'green'; }; </script> </body> </html>

i think you made some spelling mistakes, not sure tho also dont put spaces between "="我想你犯了一些拼写错误,不确定也不要在“=”之间加空格

<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>BackGround</title>
    </head>
        <body>
            <button id="red"> R </button>
            <button id="blue"> B </button>
            <button id="green"> G </button>
            <script>
                let body = document.querySelector('body');
                document.querySelector('#red').onclick = function(){
                 body.style.backgroundColor = 'red';
                };
                document.querySelector('#blue').onclick = function(){
                    body.style.backgroundColor = 'blue';
                };
                document.querySelector('#green').onclick = function(){
                    body.style.backgroundColor = 'green';
                };
                </script>
            </body>
</html>

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

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