首页 > 代码库 > 图片预览
图片预览
<!DOCTYPE html>
<html>
<head>
<title>图片预览demo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<iframe name="frm_dealer" id="iframe"></iframe>
<form action="iframe.html" target="frm_dealer" encType="multipart/form-data" id="form">
<input type="file" name="file" value="http://www.mamicode.com/shangchuan" id="file"/>
</form>
<input type="button" id="tijiao" value="http://www.mamicode.com/提交" />
<img src="" alt="tuxiang" id="img"/>
<script type="text/javascript">
document.getElementById(‘file‘).onchange = function(){
document.getElementById(‘tijiao‘).onclick = function() {
document.getElementById(‘form‘).submit();
}
}
document.getElementById("iframe").onload = function() {
var doc = document.getElementById("iframe").contentWindow.document;
var text = doc.body.getElementsByTagName(‘p‘)[0].innerHTML;
document.getElementById("img").src=http://www.mamicode.com/text;
}
</script>
</body>
</html>