使用PHP更改背景颜色

时间:2016-11-23 15:24:00

标签: javascript php jquery css css3

我制作了一个带有单选按钮和按钮的网站,所以问题是如何制作它,所以当有人选择黄色时,它会将网站的背景变为黄色。

感谢您提前提供任何帮助

<!DOCTYPE html>
<html lang="nl">
    <head>
    <meta charset="utf-8">
        <?php
        $naamnieuw = $_GET["naam"];
        $adres = $_GET["adres"];
        if ($naamnieuw || $adres == ""){
            echo "Je moet iets invullen";
        }
            else if (!empty($_GET)) {
            $naamnieuw = $_GET["naam"];
            $adres = $_GET["adres"];
            if (file_exists("vertalingen.txt")) {
            $fp = fopen("vertalingen.txt", "r+");
            fclose($fp);                
            $fp = fopen("vertalingen.txt", "a");
            fputs($fp, $naamnieuw."\r\n");
            fputs($fp, $adres."\r\n"."\r\n");
            fclose($fp);
            }                   
            else{           
            $fp = fopen("vertalingen.txt", "a");
            fputs($fp, $naamnieuw."\r\n");
            fputs($fp, $adres."\r\n"."\r\n");
            fclose($fp);

            }
        }
        ?>
    </head>
    <body>
        <form name="naamform" method="get" action="<?php echo $_SERVER["PHP_SELF"]?>">
                Word:       <input type="text" name="naam"><br>
                Translation:    <input type="text" name="adres"><br>
                            <input type="submit" name="submit" value="Toevoegen"><br><br>

        </form>
        <form action="vertalingenbekijken.php">
            <input type="submit" name="" value="Bekijken">
        </form>
        <form method="get"><br>
            <input type="radio" name="type">Rood<br>    <!--    Red     -->
            <input type="radio" name="type">Oranje<br>  <!--    Orange  -->
            <input type="radio" name="type">Geel<br>    <!--    Yellow  -->
            <input type="radio" name="type">Groen<br>   <!--    Green   -->
            <input type="radio" name="type">Blauw<br>   <!--    Blue    -->
            <input type="submit" name="" value="Change Color">
        </form>
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

<强> HTML

<input type="radio" name="type" class="type" value="red">Red<br>    <!--    Red     -->
            <input type="radio" class="type" name="type" value="orange">Orange<br>  <!--    Orange  -->
            <input type="radio" class="type" name="type" value="yellow">Yellow<br>    <!--    Yellow  -->

            <input type="radio" class="type" name="type" value="blue">Blue<br> 

<强> Jquery的

$(document).ready(function() {

        $('.type').change(function() {

           var value = $( 'input[name=type]:checked' ).val();
           alert(value);
             $("body").css({"backgroundColor" : value });
        });
    });

jsfiddle