Html 背景色如何切换为单击方形?

Html 背景色如何切换为单击方形?,html,colors,background,Html,Colors,Background,我有以下代码: <body> <DIV id="div1" style="position:absolute; top:0px;left:0px;width:320px;height:210px;"> <DIV style="background-color:#DB97F2;position:absolute;top:10px;left:10px; width:90px;height:90px"></

我有以下代码:

<body>

<DIV id="div1" style="position:absolute;
      top:0px;left:0px;width:320px;height:210px;">
    <DIV style="background-color:#DB97F2;position:absolute;top:10px;left:10px;
                width:90px;height:90px"></div>
    <DIV style="background-color:blue;position:absolute;top:10px;left:110px;
                width:90px;height:90px"></DIV>
    <DIV style="background-color:yellow;position:absolute;top:10px;left:210px;
                width:90px;height:90px"></DIV>
    <DIV style="background-color:#DB5432;position:absolute;top:110px;left:10px;
                width:90px;height:90px"></DIV>
    <DIV style="background-color:red;position:absolute;top:110px;left:110px;
                width:90px;height:90px"></DIV>
    <DIV style="background-color:green;position:absolute;top:110px;left:210px;
                width:90px;height:90px"></DIV>
</DIV>
我想通过点击彩色方块来改变壁纸。

背景色应该是每个正方形的颜色


有人能帮我吗?

您可能想研究javascript及其框架JQuery,以便在您的网页中添加交互性,但您已经对任何JQuery有了预先的了解。这就是您将如何做到的:

$('#yourSquare').click(function () {
    $('body').css("background-color", "blue"); // Just add any color you wis
});
对所有会改变页面背景颜色的方块执行此操作,只需更改选择器中的div以与方块相对应

如果您想学习javascript,请链接:


希望这有帮助:

嗨。要使html代码具有交互性,您可能需要看看Javascript。网上有几个很棒的教程!然而,jQuery是一种可能有用的特定javascript资源。祝你好运你好,谢谢你的评论。不幸的是,我被告知我不能使用jQuery。这闻起来很像一个作业。我们不想剥夺你解决这个问题的兴奋感,但是HTML5中的一个暗示会涉及到Okey。你有什么限制?你不能使用javascript,或者只使用jQuery?事实上,这是我需要解决的一个问题。口号说不仅要使用jQuery。我不想解决这个活动。我只需要知道我可以使用,因为这样会说事件处理函数将放在哪里?。