Javascript 点击我按钮

Javascript 点击我按钮,javascript,html,css,Javascript,Html,Css,我不知道我在这里做错了什么,但是单击我按钮不起作用为什么?我想在第一个点击我改变第一段的颜色,第二个点击我改变第二段的颜色。在任何情况下,单击都不起作用。我必须查看我的函数,但看不出我做错了什么。也许需要创建其他功能使其工作?仅此而已,单击按钮无法处理该代码 <!DOCTYPE html> <html> <head> <h1>Tv Shows</h1> <div class="bg-image

我不知道我在这里做错了什么,但是
单击我
按钮不起作用为什么?我想在第一个点击我改变第一段的颜色,第二个点击我改变第二段的颜色。在任何情况下,单击都不起作用。我必须查看我的函数,但看不出我做错了什么。也许需要创建其他功能使其工作?仅此而已,单击按钮无法处理该代码

<!DOCTYPE html>
    <html>
    <head>
    <h1>Tv Shows</h1>


    <div class="bg-image img1">
      <p id="demo">My Top 5 Tv shows,is Prison Break,Wayward Pines,Mentalist,Lost,Usa shooter</p>
      <button onclick="myFunction()">click me</button>
    </div>
    <div class="bg-image img2">
      <p id="demo1">My Top 5 movies,is Run all Night ,Asterix and Obelix,,Lost,Usa
      shooter</p>
      <button onclick="myFunction()">click me</button>
    </div>
    <style>

    body, html {
      height: 100%;
      margin: 0;
      font-family: Arial, Helvetica, sans-serif;
    }

    * {
      box-sizing: border-box;
    }

    .bg-image {
      /* Full height */
      height: 50%; 

      /* Center and scale the image nicely */
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }

    /* Images used */
    .img1 { background-image: url("https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); }
    .img2 { background-image: url("https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); }


    /* Position text in the middle of the page/image */
    .bg-text {
      background-color: rgb(0,0,0); /* Fallback color */
      background-color: rgba(0,0,0, 0.4); /* Black w/opacity/see-through */
      color: white;
      font-weight: bold;
      font-size: 80px;
      border: 10px solid #f1f1f1;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      z-index: 2;
      width: 300px;
      padding: 20px;
      text-align: center;
    }
    function myFunction() {
      var x = document.getElementById("demo");
      x.style.fontSize = "25px"; 
      x.style.color = "red"; 
    }

    function mySec() {
      var x = document.getElementById("demo1");
      x.style.fontSize = "25px"; 
      x.style.color = "green"; 
    }

    </style>
    </head>
    <body>



    </body>
    </html>

电视节目

我最喜欢的5个电视节目是《越狱》、《任性的松树》、《精神论者》、《迷失》、《美国射手》

点击我

我最喜欢的5部电影是通宵放映的,分别是《迷失》,美国 射手

点击我 正文,html{ 身高:100%; 保证金:0; 字体系列:Arial、Helvetica、无衬线字体; } * { 框大小:边框框; } .bg图像{ /*全高*/ 身高:50%; /*将图像居中并精确缩放*/ 背景位置:中心; 背景重复:无重复; 背景尺寸:封面; } /*使用的图像*/ .img1{背景图像:url(“https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } .img2{背景图像:url(“https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } *在页面/图像中间位置的文本*/ .bg文本{ 背景色:rgb(0,0,0);/*回退色*/ 背景色:rgba(0,0,0,0.4);/*黑色w/不透明度/透明*/ 颜色:白色; 字体大小:粗体; 字号:80px; 边框:10px实心#f1f1; 位置:固定; 最高:50%; 左:50%; 转换:翻译(-50%,-50%); z指数:2; 宽度:300px; 填充:20px; 文本对齐:居中; } 函数myFunction(){ var x=document.getElementById(“演示”); x、 style.fontSize=“25px”; x、 style.color=“红色”; } 函数mySec(){ var x=document.getElementById(“demo1”); x、 style.fontSize=“25px”; x、 style.color=“绿色”; }
仅使用标记脚本一些代码/脚本

函数myFunction(){
var x=document.getElementById(“演示”);
x、 style.fontSize=“25px”;
x、 style.color=“红色”;
}
函数mySec(){
var x=document.getElementById(“demo1”);
x、 style.fontSize=“25px”;
x、 style.color=“绿色”;
}

电视节目

我最喜欢的5个电视节目是《越狱》、《任性的松树》、《精神论者》、《迷失》、《美国射手》

点击我

我最喜欢的5部电影是通宵放映的,分别是《迷失》,美国 射手

点击我 正文,html{ 身高:100%; 保证金:0; 字体系列:Arial、Helvetica、无衬线字体; } * { 框大小:边框框; } .bg图像{ /*全高*/ 身高:50%; /*将图像居中并精确缩放*/ 背景位置:中心; 背景重复:无重复; 背景尺寸:封面; } /*使用的图像*/ .img1{背景图像:url(“https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } .img2{背景图像:url(“https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } *在页面/图像中间位置的文本*/ .bg文本{ 背景色:rgb(0,0,0);/*回退色*/ 背景色:rgba(0,0,0,0.4);/*黑色w/不透明度/透明*/ 颜色:白色; 字体大小:粗体; 字号:80px; 边框:10px实心#f1f1; 位置:固定; 最高:50%; 左:50%; 转换:翻译(-50%,-50%); z指数:2; 宽度:300px; 填充:20px; 文本对齐:居中; }
你能这样试试吗?我编辑了错误的标签

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <style>
        body,
        html {
            height: 100%;
            margin: 0;
            font-family: Arial, Helvetica, sans-serif;
        }

        * {
            box-sizing: border-box;
        }

        .bg-image {
            /* Full height */
            height: 50%;

            /* Center and scale the image nicely */
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
        }

        /* Images used */
        .img1 {
            background-image: url("https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
        }

        .img2 {
            background-image: url("https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
        }


        /* Position text in the middle of the page/image */
        .bg-text {
            background-color: rgb(0, 0, 0);
            /* Fallback color */
            background-color: rgba(0, 0, 0, 0.4);
            /* Black w/opacity/see-through */
            color: white;
            font-weight: bold;
            font-size: 80px;
            border: 10px solid #f1f1f1;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 2;
            width: 300px;
            padding: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>Tv Shows</h1>
    <div class="bg-image img1">
        <p id="demo">My Top 5 Tv shows,is Prison Break,Wayward Pines,Mentalist,Lost,Usa shooter</p>
        <button onclick="myFunction()">click me</button>
    </div>
    <div class="bg-image img2">
        <p id="demo1">My Top 5 movies,is Run all Night ,Asterix and Obelix,,Lost,Usa
            shooter</p>
        <button onclick="myFunction()">click me</button>
    </div>

    <script>
        function myFunction() {
            var x = document.getElementById("demo");
            x.style.fontSize = "25px";
            x.style.color = "red";
        }

        function mySec() {
            var x = document.getElementById("demo1");
            x.style.fontSize = "25px";
            x.style.color = "green";
        }
    </script>
</body>

</html>

身体
html{
身高:100%;
保证金:0;
字体系列:Arial、Helvetica、无衬线字体;
}
* {
框大小:边框框;
}
.bg图像{
/*全高*/
身高:50%;
/*将图像居中并精确缩放*/
背景位置:中心;
背景重复:无重复;
背景尺寸:封面;
}
/*使用的图像*/
.img1{
背景图像:url(“https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
}
.img2{
背景图像:url(“https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
}
*在页面/图像中间位置的文本*/
.bg文本{
背景色:rgb(0,0,0);
/*退色*/
背景色:rgba(0,0,0,0.4);
/*黑色w/不透明度/透明*/
颜色:白色;
字体大小:粗体;
字号:80px;
边框:10px实心#f1f1;
位置:固定;
最高:50%;
左:50%;
转换:翻译(-50%,-50%);
z指数:2;
宽度:300px;
填充:20px;
文本对齐:居中;
}
电视节目

我最喜欢的5个电视节目是《越狱》、《任性的松树》、《精神论者》、《迷失》、《美国射手》

点击我

我最喜欢的5部电影是通宵放映的,分别是《迷失》,美国 射手

点击我 函数myFunction(){ 变量x
<!DOCTYPE html>
<html>
    <head>
        <style>
body, html { height: 100%; margin: 0; font-family: Arial, Helvetica, sans-serif; } * { box-sizing: border-box; } .bg-image { /* Full height */ height: 50%; /* Center and scale the image nicely */ background-position: center; background-repeat: no-repeat; background-size: cover; } /* Images used */ .img1 { background-image: url("https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } .img2 { background-image: url("https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"); } /* Position text in the middle of the page/image */ .bg-text { background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0, 0.4); /* Black w/opacity/see-through */ color: white; font-weight: bold; font-size: 80px; border: 10px solid #f1f1f1; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; width: 300px; padding: 20px; text-align: center; }
</style>

<script> function myFunction() { var x = document.getElementById("demo"); x.style.fontSize = "25px"; x.style.color = "red"; } function mySec() { var x = document.getElementById("demo1"); x.style.fontSize = "25px"; x.style.color = "green"; }
</script>
    </head>
    <body>
        <h1>Tv Shows</h1>
        <div class="bg-image img1">
            <p id="demo">My Top 5 Tv shows,is Prison Break,Wayward Pines,Mentalist,Lost,Usa shooter</p>
            <button onclick="myFunction()">click me</button>
        </div>
        <div class="bg-image img2">
            <p id="demo1">My Top 5 movies,is Run all Night ,Asterix and Obelix,,Lost,Usa shooter</p>
            <button onclick="myFunction()">click me</button>
        </div>
    </body>
</html>
<html>

<head>

    <style>
        body,
        html {
            height: 100%;
            margin: 0;
            font-family: Arial, Helvetica, sans-serif;
        }

        * {
            box-sizing: border-box;
        }

        .bg-image {
            /* Full height */
            height: 50%;
            /* Center and scale the image nicely */
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
        }
        /* Images used */

        .img1 {
            background-image: url("https://images.pexels.com/photos/1115804/pexels-photo-1115804.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
        }

        .img2 {
            background-image: url("https://images.pexels.com/photos/3989816/pexels-photo-3989816.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
        }
        /* Position text in the middle of the page/image */

        .bg-text {
            background-color: rgb(0, 0, 0);
            /* Fallback color */
            background-color: rgba(0, 0, 0, 0.4);
            /* Black w/opacity/see-through */
            color: white;
            font-weight: bold;
            font-size: 80px;
            border: 10px solid #f1f1f1;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 2;
            width: 300px;
            padding: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <h1>Tv Shows</h1>
    <div class="bg-image img1">
        <p id="demo">My Top 5 Tv shows,is Prison Break,Wayward Pines,Mentalist,Lost,Usa shooter</p>
        <button onclick="myFunction('demo')">click me</button>
    </div>
    <div class="bg-image img2">
        <p id="demo1">My Top 5 movies,is Run all Night ,Asterix and Obelix,,Lost,Usa shooter
        </p>
        <button onclick="myFunction('demo1')">click me</button>
    </div>

    <script>
        function myFunction(id) {
            var x = document.getElementById(id);
            x.style.fontSize = "25px";
            x.style.color = "red";
        }
    </script>
</body>

</html>