Jquery Selecting image

前端 未结 5 1072
孤街浪徒
孤街浪徒 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:42

    Do you mean:

    
    $.fn.hasBorder = function() {   
      if ((this.outerWidth() - this.innerWidth() > 0) ||  (this.outerHeight() - this.innerHeight() > 0)){
            return true;
        }
        else{
            return false;
        }
    };
    $(document).ready(function() {
      var selectedImgsArr = [];
       $("img").click(function() {
    
          if($(this).hasBorder()) {
              $(this).css("border", "");
              //you can remove the id from array if you need to
          }
          else {
             $(this).css("border", "1 px solid red");
             selectedImgsArr.push($(this).attr("id")); //something like this 
          }
       });
    });
    

提交回复
热议问题