背景图片的两个事件

问题描述 投票:1回答:1

我正在尝试通过单击图片或单击按钮来创建某些东西来更改墙纸。

另外它是可行的,但是当我单击缩略图墙纸更改并且当我单击按钮时,我选择了一张图片就可以了,但是如果我想再次单击缩略图,问题就会出现,如果有人可以帮助我,非常感谢。

我创建了一个example

$('ul#images li').click(function(e){
  $('ul#images li').each(function(){
      $(this).removeClass('active');
  });  
    $(this).addClass('active');
    var source = $(this).children('img').attr('src');
    $('.outer').css('background', 'url('+source+')');
});

$(function () {
    $(":file").change(function () {
        if (this.files && this.files[0]) {
            var reader = new FileReader();
            reader.onload = imageIsLoaded;
            reader.readAsDataURL(this.files[0]);
        }
    });
});
function imageIsLoaded(e) {
    $('#myImg').attr('src', e.target.result);
}
javascript jquery-events
1个回答
0
投票

单击图片设置.outer div的背景,按钮设置图像标签的背景。为什么还没有为.outer div设置背景呢?然后完全删除图像标签。我认为这样就可以按您期望的那样工作,下面的示例。

© www.soinside.com 2019 - 2024. All rights reserved.