首页 > 代码库 > jq1 颜色填充器

jq1 颜色填充器

1.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title> 颜色填充div</title>
    <script src="http://www.mamicode.com/jquery-1.12.3.min.js"></script>
    <style>
        div{width:100px;height: 100px; border: 1px solid black; float: left; margin: 10px}
    </style>
</head>
<body>
<span>red</span>
<span>yellow</span>
<span>green</span>
<span>black</span><br/>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
    var color = "";
     $(‘span‘).click(function(){
        color =  $(this).html();
     });
    $(‘div‘).click(function(){
        $(this).css(‘background‘,color);
    });
</script>
</body>
</html>

 

jq1 颜色填充器