Jquery选择图像

标签 jquery

首先,我是 Jquery 新手。

我有这样的图片。我想要的是,当用户单击图像时,它会使图像带有边框。用户可以选择多个图像。选择时所有内容都必须带有边框。单击按钮后,我将获得图像 ID。

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

enter image description here

我该怎么做?

最佳答案

你的意思是:


$.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选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10170280/

相关文章:

javascript - Jquery closest and find 似乎不起作用

jquery - jQuery 中的 Zoomify 等效项?

javascript - 如何使用 jQuery 将有限的值插入到 html 表的每一行中

javascript - 在ajax中获取响应参数值

jquery - 单击一个时如何关闭其他 Accordion ,以及如何在隐藏父级时隐藏描述?

javascript - 警报到来时组合框消失

javascript - swarminject 是做什么用的?

c# - .NET MVC - 为 jPlayer 返回视频文件

javascript - 如何获取数据表列的名称?

javascript - jQuery 数据表导出到 excelHtml5 HYPERLINK 问题