Jquery и начальная загрузка модальной Uncaught TypeError: $ .alert не является функцией - PullRequest
0 голосов
/ 28 января 2019

Сценарий ниже запускается, когда файл выбран для загрузки.Если выбранная ширина и высота файла изображения не соответствуют данным поиска данных, отображается предупреждение.До того, как перегрузить мой сайт с помощью Bootstrap, просто Jquery хорошо работал.Теперь я представил Bootstrap. Я получаю сообщение об ошибке:

Uncaught TypeError: $ .alert не является функцией в строке 24

window.URL    = window.URL || window.webkitURL;
var elBrowse  = document.getElementById("browse"),
elPreview = document.getElementById("preview4"),
elPreviewtext = document.getElementById("previewtext"),
useBlob   = false && window.URL;

function readImage (file) {
  // Create a new FileReader instance
  var reader = new FileReader();
  // Once a file is successfully readed:
  reader.addEventListener("load", function () {
    var image  = new Image();
      image.addEventListener("load", function () {
      // Concatenate our HTML image info
      var imageInfo = file.name;
      if ( image.width != w && image.height != h ) {
        $.alert({ ///////// LINE 24 /////////
          title: 'Image select error!',
          content: 'The image you have seleted is incorrect, ' + image.width + ' by ' + image.height + ' portrate.<br/><br/> Please resize your image to the correct size in landscape.<br/><br/>Resizing upwards reduces the quality of the image. Start with a large image and resize downwards.<br/><br/>For help read section 1.5 in the knowledgebase',
          icon: 'fa fa-rocket',
          animation: 'zoom',
          boxWidth: '50%',
          closeAnimation: 'zoom',
          buttons: {
            okay: {
              text: 'Try again',
              btnClass: 'btn-blue'
            }
          }
        });

       } else {
             var imageInfotext = 'Display width: '+ image.width  +',<br/>Display height: '+ // But get the width from our `image`
         image.height;

          // Finally append our created image and the HTML info string to our `#preview`
          elPreview.appendChild( this );
          elPreview.insertAdjacentHTML("beforeend", imageInfo +'<br>');
          elPreviewtext.insertAdjacentHTML("beforeend", imageInfotext +'<br>');
              if (useBlob) {
            // Free some memory for optimal performance
            window.URL.revokeObjectURL(image.src);
          }
        }
      });
    image.src = useBlob ? window.URL.createObjectURL(file) : reader.result;
});
reader.readAsDataURL(file);
}
// Once the user selects all the files to upload
// that will trigger a `change` event on the `#browse` input
elBrowse.addEventListener("change", function() {
var files  = this.files;
var errors = "";
if (!files) {
errors += "File upload not supported by your browser.";
}
// Check for `files` (FileList) support and if contains at least one file:
if (files && files[0]) {

// Iterate over every File object in the FileList array
for(var i=0; i<files.length; i++) {

// Refer to the current File as a `file` variable

var file = files[i];

// Test the `file.name` for a valid image extension:
// (pipe `|` delimit more image extensions)
// The regex can also be expressed like: /\.(png|jpe?g|gif)$/i
if ( (/\.(png|swf|jpg)$/i).test(file.name) ) {
// SUCCESS! It's an image!
// Send our image `file` to our `readImage` function!
readImage( file );
} else {


$('#imageis').hide();
$.alert({
title: 'Image select error!',
content: 'Unsupported Image extension, ' + file.name + '.<br/><br/> Supported file extensions are:.<br/><br/>.png for an image file<br/>.swf for a Adobe Flash file',
icon: 'fa fa-rocket',
animation: 'zoom',
boxWidth: '50%',
closeAnimation: 'zoom',

buttons: {
okay: {
text: 'Try again',
btnClass: 'btn-blue'
}
}
});

}
}
}
});

Большое спасибо заранее за ваше время.

1 Ответ

0 голосов
/ 28 января 2019

Я не был знаком с методом с именем $.alert(), поэтому немного исследований позже, и я думаю, что ваш код намеревается использовать этот тип формата:

$(".close").click(function(){
   $("#myAlert").alert("close");
});

или, возможно, выиспользуя плагин jQuery, о котором вы не упомянули.

Похоже, вы используете плагин подтверждения jQuery - это правильно?Что-нибудь случилось с HTML-ссылкой на код этого плагина?( что вызовет такую ​​ошибку ... )

...