Jquery Selecting image

前端 未结 5 1017
孤街浪徒
孤街浪徒 2021-01-07 06:06

primarily, i\'m new for Jquery.

I have images like that . What i want is that when user click image,it makes image bordered. User can select a number of images. It

5条回答
  •  一生所求
    2021-01-07 06:27

    first add a class for selections and then add items to array which have 'selected-image' class while form posted

    $(document).ready(function() {
      var selectedImgsArr = new Array();
       $("img").click(function() {
    
          if($(this).hasClass("selected-image"))
               $(this).removeClass("selected-image");
          else
               $(this).addClass("selected-image");
       });
       $("form").submit(function(){
           selectedImgsArr.push($(".selected-image").attr("src"));
       })
    });
    

提交回复
热议问题