Image preview opens for duplicated div

前端 未结 3 1140
小蘑菇
小蘑菇 2021-01-26 00:24

I have a function that uploads and image and adds a preview to this image, and i have two buttons, when i click on the first one it clicks on the input type file and opens it, a

3条回答
  •  梦谈多话
    2021-01-26 00:46

    you can append the element instead of duplicating it. you can change the classes and ids using variables.

    $('.duplicate').click(function() {
      var newClass="new-class";
      var toAppendElement = '
    ' + '' + '' + 'Your Image' + '

    '; $(".cloned").append(toAppendElement); })

    http://jsfiddle.net/8h3gcyhz/

提交回复
热议问题