Jquery选择图像

Mer*_*TİN 2 jquery

主要是,我是Jquery的新手.

我有这样的图像.我想要的是,当用户点击图像时,它会使图像边界化.用户可以选择多个图像.选中时必须全部接壤.单击按钮后,我将有图像ID.

  <tr><img id="i will put value for db processing"src="urlofimage"</tr> &nbsp;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我怎样才能做到这一点?

Sud*_*oti 6

你的意思是:


$.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 
      }
   });
});
Run Code Online (Sandbox Code Playgroud)