复制代码代码如下: 关于File !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head title /title script src="../jquery-1.7.1.js" type="text/javascript" /script script type="text/javascript" $(document).ready(function () { $('#wl').click(function () { var f = $('#file')[0];
复制代码代码如下: 我是一个小实验 !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head title /title script src="../jquery-1.7.1.js" type="text/javascript" /script script type="text/javascript" $(document).ready(function () { var bt = $('#wl'); var file = $('#file'); var type = $('#type'); var result = $('#result');
var func = {}; func.readAsDataURL = function (file) { //验证是否为图片 if (!/image///w+/.test(file.type)) { alert('非图片格式'); return false; } var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function (e) { result.html(' img src="' + this.result + '"/ } }
func.readAsBinaryString = function (file) {
var reader = new FileReader(); reader.readAsBinaryString(file);