jQuery点击小图展示大图


<html>
    <head>
        <meta charset="UTF-8">
        <title>title>
        <script type="text/javascript" src="js/jquery-3.2.1.min.js" >script>
        <style>
            #div1{
                width: 266px;
                height: 200px;
                border: 2px solid red;
            }
            #div2{
                width: 266px;
                height: 50px;
            }
            img{
                width: 50px;
                height: 50px;
            }
        style>
    head>
    <body>
        <div id="div1"><img id="img1" style="width: 266px;height: 200px;"/>div>
        <div id="div2">
            <img src="img/q3.jpg" />
            <img src="img/q4.jpg" />
            <img src="img/q5.jpg" />
            <img src="img/q6.jpg" />
            <img src="img/q7.jpg" />
        div>

        <script>
            $("#div1").hide();
            $("img").click(function(){
                $("#div1").children().removeAttr("src")
                $("#div1").show();
                var sr = $(this).attr("src");
                $("#img1").attr("src",sr);
            })
        script>
    body>
html>

你可能感兴趣的:(jQuery点击小图展示大图)