将 JavaScript 更改事件转换为 jQuery
convert javascript change event to jquery
有一个函数可以在HTML 5中处理文件,但它在javascript中我必须将其更改为jquery函数
<style>
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
这将在本地创建从输入图像翻滚所以我需要更改它才能在 jquery 中工作喜欢这个:
$('#thisfile').change(function(){
handleFileSelect(this)
});
但是当我运行 jquery 函数时,它显示TypeError: evt.target is undefined
错误如何在此处提供 jQuery 函数参数?
$('#thisfile').change(function(evt){
handleFileSelect(evt);
});
相关文章:
- 从javascript到jquery的转换
- 如何使用jquery将base64图像路径转换为真实路径
- 将curl查询转换为jQuery.ajax()
- 将jQuery.ech()方法转换为本地JavaScript抽象的最佳方法是什么
- 如何使用JQuery在Javascript中转换字符串中的HTML元素
- js代码从jQuery转换为原生代码
- javascript/jquery将utc转换为短格式的本地时间
- 将jQuery转换为用户脚本的普通Javascript时遇到问题
- 将javascript代码转换为jquery代码时出错
- CSS3转换+jQuery翻转卡问题
- 转换jquery的悬停点击事件
- 正在转换JQuery对象
- 如何在一个AngularJS指令中转换jQuery函数
- 如何转换jquery's$.post()转换为纯javascript
- 在mootools中转换jquery代码
- 如何转换jQuery $.ajax调用蓝鸟承诺没有延迟的反模式
- 如何转换jQuery过滤器以使用waitForKeyElements
- 转换 jQuery 对象中的 lodash/underscore 集合(链接)
- 转换jquery "click"用于PHP调用的代码
- 转换jQuery函数,使其易于重用而无需重复