<body> <input type="file" name="file" id="file" onClick="$(‘#file‘).click();" style="display:block" onChange="var img=getObjectURL(this.files[0]);$(‘#myimg‘).attr(‘src‘,img)" /> <img id="myimg" src="" style="pointer-events: none;"/> </body> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> function getObjectURL(file) { var url = null ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } return url ; }; </script>
时间: 2024-12-28 17:02:25