Yüklenen görüntü geçerli olup olmadığını bir hatayı veya başarıyı bir uyarı kutusu alma konusunda olsun doğrular benim jQuery bitjQuery görüntü atma geçersiz görüntü türü ve burada
gösterilmektedir edilir yerine uyarı kutusunun geçersiz bir ileti göster eğerİhtiyaç çözümü için: yerine başarı veya hata işlevi bir hata varsa
- mesajla
jQuery bit:
(function($) {
$.fn.checkFileType = function(options) {
var defaults = {
allowedExtensions: [],
success: function() {},
error: function() {}
};
options = $.extend(defaults, options);
return this.each(function() {
$(this).on('change', function() {
var value = $(this).val(),
file = value.toLowerCase(),
extension = file.substring(file.lastIndexOf('.') + 1);
if ($.inArray(extension, options.allowedExtensions) == -1) {
options.error();
$(this).focus();
} else {
options.success();
}
});
});
};
})(jQuery);
function validate() {
$('#filen').checkFileType({
allowedExtensions: ['jpg', 'jpeg', 'png', 'bmp'],
success: function() {
$("#filen").text("Valid image").show();
},
error: function() {
/*messages: {
filen: "Please insert valid image file with following extensions .jpg .jpeg .png .bmp"
},*/
alert('Error: Please insert valid image file with following extensions .jpg .jpeg .png .bmp');
reload("index134.html");
}
});
html bit: - Ayrı eleman oluşturabilir mesaj kısmı için
<tr>
<td><label>Insert File</label></td>
<td><input type="file" name="filen" id ="filen"/></td>
</tr>
Mesaj? –
Geçerli bir resim dosyası/geçersiz resim dosyası gibi –
Uyarı yerine mesaj? Bu mesajı nasıl görmek istersiniz? –