作者信息:
Author:airzen
QQ:39192170
E-mail:airzen@sohu.com
转贴请保留作者信息,谢谢
<input name="w_s" type="file" id="w_s" onChange="load_img(this.value,img_s);">
<input name="w_b" type="file" id="w_b" onChange="load_img(this.value,img_b);">
<div id="img_s"></div>
<div id="img_b"></div>
<script language="javascript">
<!--
function load_img(p_src,write_id){
var t_html;
if(p_src!=''){
if(write_id==img_s){
t_html="<img src='"+p_src+"' onLoad='javascript:if(this.width>120){this.width=120;}if(this.height>120){this.height=120;}'>";
}else{
t_html="<img src='"+p_src+"' onLoad='javascript:if(this.width>240){this.width=240;}if(this.height>240){this.height=240;}'>";
}
}else{
t_html="";
}
write_id.innerHTML=t_html;
}
//-->
</script>
博客展示了通过HTML的文件输入框和JavaScript函数实现图片加载的代码。利用HTML的input标签创建文件选择框,当选择文件时触发JavaScript的load_img函数,该函数根据选择的文件路径生成对应尺寸的图片并显示。
629

被折叠的 条评论
为什么被折叠?



