You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.3 KiB

  1. /**
  2. * Created by admin on 2016/11/3.
  3. */
  4. //加载图片类型数组
  5. function load_img_type() {
  6. $.ajax({
  7. url: base_api + 'carManager/index.php', //请求地址
  8. data: {
  9. tp: "carControl_getImgType"
  10. },
  11. type: "post", //请求方式
  12. dataType: "json",
  13. success: function (data) {
  14. console.log(data);
  15. if (data.code == 0) {
  16. data = data.data;
  17. var temp = '<option value="0">请选择</option>';
  18. for (var i = 0, j = data.length; i < j; i++) {
  19. temp += '<option value="' + data[i].id + '">' + data[i].img_status + '</option>';
  20. }
  21. $(".bus_img_type").html(temp);
  22. } else {
  23. ZZAlertInfo(data.info);
  24. }
  25. }
  26. });
  27. }
  28. $("div.bus_img_group").on('change', '.bus_img_path', function (e) {
  29. //图片如果太大,提示
  30. // 取消按钮也会触发
  31. var img = $(this).closest('.bus_img_div').find('.bus_image');
  32. if (this.files.length > 0) {
  33. if (this.files[0]['size'] > 20000000) {
  34. this.value = '';
  35. ZZAlertInfo('图片大小必须在2M以下');
  36. return true;
  37. }
  38. //复制前一个div,设置值为空
  39. if ($(".bus_img_group .bus_image[class='bus_image']").length == 1) {
  40. var newImg = $(this).closest('.bus_img_div').clone();
  41. $(newImg).find('input').val('');
  42. $(".bus_img_group").append(newImg);
  43. }
  44. readURL(e, this);
  45. img.html('-');
  46. img.addClass('bus_img_remove');
  47. $(img).closest('.bus_img_div').find('.bus_img_path_old').val('');
  48. } else {
  49. removeImg(img);
  50. }
  51. })
  52. $(".bus_img_group").on('click', '.bus_image', function () {
  53. if ($(this).hasClass('bus_img_remove'))
  54. removeImg($(this).closest('.bus_img_div').find('.bus_image'));
  55. else
  56. $(this).closest('.bus_img_div').find('.bus_img_path').click();
  57. })
  58. function readURL(event, o) {
  59. var getImagePath = URL.createObjectURL(event.target.files[0]);
  60. $(o).closest('.bus_img_div').find('.bus_image').css('background-image', 'url(' + getImagePath + ')');
  61. }
  62. function removeImg(img) {
  63. $(img).css('background-image', '');
  64. $(img).html('+');
  65. $(img).removeClass('bus_img_remove');
  66. $(img).closest('.bus_img_div').find('input').val('');
  67. }