<
div
class
=
“upload_box”
>
<
b
>
上传图片
</
b
>
<
input
type
=
“file”
name
=
“file”
id
=
“file”
accept
=
“image/*”
onchange
=
“imgChange(this);”
/>
<!–文件上传选择按钮–>
<
div
id
=
“preview”
>
<
img
id
=
“imghead”
src
=
“/style/images/blank.gif”
width
=
“260”
height
=
“180”
/> <!–图片显示位置–>
</
div
>
</
div
>
<
script
type
=
“text/javascript”
>
// 选择图片显示
function
imgChange
(
obj
) {
//获取点击的文本框
var
file
=
document
.
getElementById
(
“file”
);
var
imgUrl
=
window
.
URL
.
createObjectURL
(
file
.
files
[
0
]);
var
img
=
document
.
getElementById
(
‘imghead’
);
img
.
setAttribute
(
‘src’
,
imgUrl
); // 修改img标签src属性值
};
<
/
script
>
版权声明:本文为qq_27367825原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。