checkimg.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. $.fn.initCheckImg = function (imgdata, oldimg, width, height) {
  2. var imgInfo = null;
  3. if(imgdata && imgdata.length > 0) {
  4. $.extend(imgdata[0]);
  5. var imgstr = '';
  6. if (oldimg) {
  7. imgdata.map(function (item, index) {
  8. if (item.Id == oldimg.Id) {
  9. imgInfo = {
  10. Id: item.Id,
  11. Class: item.IconClass
  12. };
  13. $.ImgInfo = imgInfo;
  14. imgstr += '<div class="imgbox true" id="' + item.Id + '" style="width:' + width + ';height:' + height + '"><i class="' + item.IconClass + '"></i><span class="ifcheck"></span></div>';
  15. } else {
  16. imgstr += '<div class="imgbox" id="' + item.Id + '" style="width:' + width + ';height:' + height + '"><i class="' + item.IconClass + '"></i><span class="ifcheck"></span></div>';
  17. }
  18. });
  19. } else {
  20. imgdata.map(function (item, index) {
  21. if (index === 0) {
  22. imgInfo = {
  23. Id: item.Id,
  24. Class: item.IconClass
  25. };
  26. $.ImgInfo = imgInfo;
  27. imgstr += '<div class="imgbox true" id="' + item.Id + '" style="width:' + width + ';height:' + height + '"><i class="' + item.IconClass + '"></i><span class="ifcheck"></span></div>';
  28. } else {
  29. imgstr += '<div class="imgbox" id="' + item.Id + '" style="width:' + width + ';height:' + height + '"><i class="' + item.IconClass + '"></i><span class="ifcheck"></span></div>';
  30. }
  31. });
  32. }
  33. imgstr = '<div class="checkImgBox clearfix" style="height:100%;">' + imgstr + '</div>';
  34. $(this).html(imgstr);
  35. $(this).find('.imgbox').click(function() {
  36. $(this).addClass('true').siblings().removeClass('true');
  37. imgInfo = {
  38. Id: $(this).attr("id"),
  39. Class: $(this).find('i').attr('class')
  40. };
  41. $.extend({
  42. ImgInfo: imgInfo
  43. });
  44. });
  45. } else {
  46. console.log('数组参数错误');
  47. }
  48. }