HTML READFILE

WEB前端 waitig 495℃ 百度已收录 0评论
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">        
        if(typeof FileReader == "undified") {
            alert("OLD BROSWER");
        }
        function showDataByURL() {
            var resultFile = document.getElementById("fileDemo").files[0];
            if (resultFile) {
                var reader = new FileReader();                
                reader.readAsDataURL(resultFile);
                reader.onload = function (e) {
                    var urlData = this.result;
                    document.getElementById("result").innerHTML += "<img src='" + urlData + "' alt='" + resultFile.name + "' />";
                }; 
            }
        } 
        function showDataByBinaryString() {
              var resultFile = document.getElementById("fileDemo").files[0];
            if (resultFile) {
                var reader = new FileReader();
                reader.readAsBinaryString(resultFile);
                reader.onload = function(e) {
                    var urlData = this.result;
                    document.getElementById("result").innerHTML += urlData;
                };
            }
        }
        function showDataByText() {
            var resultFile = document.getElementById("fileDemo").files[0];
            if (resultFile) {
                var reader = new FileReader();
                reader.readAsText(resultFile,'UTF-8');
                reader.onload = function (e) {
                    var urlData = this.result;
                    alert(urlData);
                    document.getElementById("result").innerHTML += urlData;
                };
            }
        }
    </script>
</head>
<body>
<input type="file" name="fileDemo" id="fileDemo" multep/><input type="button" value="readAsDataURL" id="readAsDataURL" onclick="showDataByURL();"/><input type="button" value="readAsBinaryString" id="readAsBinaryString" onclick="showDataByBinaryString();"/><input type="button" value="readAsText" id="readAsText" onclick="showDataByText();"/>
<div id="result">
</div>
</body>
</html>

本文由【waitig】发表在等英博客
本文固定链接:HTML READFILE
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)