0

我怎样才能缩短它以使其全部适合一个功能。我有一个工作图像库,当单击具有类 a 的图像时,类 bigimg 中的图像更改为选定的图像。我可能已经做了很长的更改图像的工作,但最多只有十几个。

顺便说一句,我将托管我的图片,这些图片仅用于我的测试

HTML/jQuery

<div id="galleryholder">

            <div id="largeimg" class="center">
                <img class="bigimg" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg">
            </div>

            <div id="reel">
                <a href=""><img class="a" src="http://wallpaperstate.org/wp-content/gallery/ca_home/hd-wallpaper-30.jpg"></a>
                <a href="#"><img class="b" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg"></a>
                <a href="#"><img class="c" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg"></a>
            </div>

                <script>
                $(function() {

                  $('.a').click(function(){
                    $(".bigimg").attr('src',"http://wallpaperstate.org/wp-content/gallery/ca_home/hd-wallpaper-30.jpg");
                    return false;
                  });
                });


                $(function() {
                  $('.b').click(function(){
                    $(".bigimg").attr('src',"http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg");
                    return false;
                  });
                });
                </script>

        </div>
4

2 回答 2

8

src从单击的图像中动态拉取:

var $big = $(".bigimg");

$('#reel img').click(function () {
    $big.attr('src', this.src);
    return false;
});
于 2013-01-25T18:32:34.727 回答
0

        <div id="largeimg" class="center">
            <img class="bigimg" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg">
        </div>

        <div id="reel">
            <a href=""><img class="a" src="http://wallpaperstate.org/wp-content/gallery/ca_home/hd-wallpaper-30.jpg"></a>
            <a href="#"><img class="a" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg"></a>
            <a href="#"><img class="a" src="http://1.bp.blogspot.com/-BNkayp7vphQ/UEmx3WTwe1I/AAAAAAAAELg/eHu4hWtoXbk/s1600/desktop-wallpaper-29.jpg"></a>
        </div>

            <script>
            $(function() {
              $('.a').click(function(e){
                $(".bigimg").attr('src',$(this).attr('src'));
                e.preventDefault();
              });
            });
            </script>
于 2013-01-25T18:34:14.443 回答