jQuery选择图片 [英] Jquery Selecting image

查看:85
本文介绍了jQuery选择图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是Jquery的新手.

primarily, i'm new for Jquery.

我有类似的图像.我想要的是,当用户单击图像时,它使图像带有边框.用户可以选择许多图像.选中时,必须全部加边框.单击按钮后,我将获得图像ID.

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 all must be bordered when selected. After button is clicked, i will have images id.

  <tr><img id="i will put value for db processing"src="urlofimage"</tr> &nbsp;

我该怎么做?

推荐答案

您的意思是:


$.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 
      }
   });
});

这篇关于jQuery选择图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆