javascript 插入-AN-image.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 插入-AN-image.js相关的知识,希望对你有一定的参考价值。

$('#element-to-get-file').change(function (e) {
  //inputFile is the input with type = file
	var curFile = inputFile.files;
  //check if the file is attached
	if (curFile.length === 0) {
    //show error
		textTo.textContent = 'No files currently selected for upload';

	} else {
		var i = 0;

		if (validFileType(curFile[i])) {

			console.log('file is found and in a stated file type!');
			imgTo.src = window.URL.createObjectURL(curFile[i]);
			//$(imgTo).attr('src', curFile[i]);
			//var img = document.createElement('img');
			//img.src = window.URL.createObjectURL(curFile[i]);
			//$('body').append(img);

		} else {
			para.textContent = 'File name ' + curFile[i].name + ': Not a valid file type. Update your selection.';
			textTo.textContent = 'not found the file in the length';

		}
	}
});

var fileTypes = [
	'image/jpeg',
	'image/pjpeg',
	'image/png'
]

function validFileType(file) {
	for (var i = 0; i < fileTypes.length; i++) {
		if (file.type === fileTypes[i]) {
			return true;
		}
	}
	return false;
}

以上是关于javascript 插入-AN-image.js的主要内容,如果未能解决你的问题,请参考以下文章

javascript 使用JavaScript在脚本中插入脚本

javascript [插入排序] #javascript

javascript [插入排序] #javascript

JavaScript插入节点小结

JavaScript 中的 ^(插入符号)符号有啥作用?

将javascript代码插入php