تصف هذه المقالة طريقة تنفيذ تأثير معاينة الصور قبل تحميل الصور بواسطة JS. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
انسخ الرمز على النحو التالي: <! doctype html public "-// w3c // dtd html 4.01 // en" "http://www.w3.org/tr/html4/strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html ؛ charset = utf-8" />
<title> تأثير معاينة الصورة قبل تحميل الصور بواسطة JS </title>
</head>
<body>
<input id = "myfile" type = "file" />
<br />
<img src = "/images/logo.gif"/>
<div id = "info"> </viv>
<script type = "text/javaScript">
var dfile = document.getElementById ('myfile') ؛
var dimg = document.getElementSbyTagName ('img') [0] ؛
var dinfo = document.getElementById ('info') ؛
dfile.onchange = function () {
if (! dfile.value.match (/.
if (dfile.files) {
dimg.src = dfile.files [0] .getasdataurl () ؛
} آخر إذا (dfile.value.indexof ('//')> -1 || dfile.value.indexof ('//')> -1) {
dimg.src = dfile.value ؛
}
}
</script>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.