我有 4 个正方形(div)和 1 个大 div,我希望根据单击的 div 加载内容
有点像http://www.w3.org/html/logo/的“技术”部分
如何使用 javascript/jquery 做到这一点?
首先我不得不说我对 jQuery 真的很陌生。
编辑:这是供将来参考的固定版本
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
.square{
    width: 100px;
    height: 100px;
    float: left;
    background: #CCC;
}
#details{
    width: 400px;
    height: 100px;
    float: left;
    background: #999;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('.square:first').css('background-color', 'red');
    $(".square").on("click", function() {
        $('.square').css('background-color', ' #ccc');
        $(this).css('background-color','red');
        var id= 'Content for div ' + $(this).attr("contentId");
        $('#details').fadeOut(function(){
            $(this).text(id).fadeIn();
        })
    });
});
</script>
</head>
<body>
    <div class="square" contentId="c1"></div>
    <div class="square" contentId="c2"></div>
    <div class="square" contentId="c3"></div>
    <div class="square" contentId="c4"></div>
    <div id="details"></div>
    <div style="display: none" id="c1"> Content for div 1</div>
    <div style="display: none" id="c2"> Content for div 2</div>
    <div style="display: none" id="c3"> Content for div 3</div>
    <div style="display: none" id="c4"> Content for div 4</div>     
</body>
</html>