用js实现预览待上传的本地图片
发布时间:2024-06-19 13:50:35
标签:用js实现预览待上传的本地图片
<form name="form5" id="form5" method="post" action="#">
<input type="file" name="file5" id="file5" onchange="preview5()"/>
</form>
<script type="text/javascript">
function preview5(){
var x = document.getElementById("file5");
if(!x || !x.value) return;
var patn = /\.jpg$|\.jpeg$|\.gif$/i;
if(patn.test(x.value)){
var y = document.getElementById("img5");
if(y){
y.src = "file://localhost/" + x.value;
}else{
var img=document.createElement("img"); img.setAttribute("src","file://localhost/"+x.value);
img.setAttribute("width","120");
img.setAttribute("height","90");
img.setAttribute("id","img5");
document.getElementById("form5").appendChild(img);
}
}else{
alert("您选择的似乎不是图像文件。");
}}
</script>
0
投稿
猜你喜欢
- 在这个简短的教程中,我会介绍将python列表转换为字符串的不同方法。为什么要将python列表转换为字符串?将python列表转换为字符串
- 实现一个mysql数据库封装需要考虑的问题1.使用方便性采用直接sql语句操作方式。只要会写sql语句,那么将没有其他学习成本。uctphp
- 经常有需要扫描目录,对文件做批量处理的需求,所以对目录处理这块做了下学习和总结。Python 中扫描目录有两种方法:os.listdir 和
- 本文实例讲述了Python通过TensorFLow进行线性模型训练原理与实现方法。分享给大家供大家参考,具体如下:1、相关概念例如要从一个线
- Golang浮点数比较和运算会出现误差。浮点数储存至内存中时,2的-1、-2……-n次方不能精确的表示小数部分,所以再把这个数从地址中取出来
- 一、JSON.stringify介绍JSON.stringify() 方法将一个 JavaScript 对象或值转换为
- 心血来潮写了个多线程抓妹子图,虽然代码还是有一些瑕疵,但是还是记录下来,分享给大家。Pic_downloader.py# -*- codin
- 前言安全性是所有数据库管理系统的一个重要特征。理解安全性问题是理解数据库管理系统安全性机制的前提。最近和同事在做数据库权限清理的事情,主要是
- 长期以来一直以为iframe跟div一样都是块级元素,直到今天在一个群中看到一位朋友问到iframe怎么居中的时候,测试了下发现原来我一直对
- orm查询优化1)only与referonly方法返回的是一个queryset对象,本质就是列表套数据对象该对象内只含有only括号所指定的
- 1、Windows上anaconda安装配置mmdetection环境稍后再写2、将anaconda环境离线移植到另一台电脑首先将anaco
- 如下所示:import numpy as npimport matplotlib.pyplot as plt# 生成测试数据x = np.l
- 描述给定一个序列(至少含有 1 个数),从该序列中寻找一个连续的子序列,使得子序列的和最大。 例如,给定序列 [-2,1,-3,4,-1,2
- python用terminal输入参数import argparseif __name__ == '__main__':pa
- 目录1.jupyter简介2.jupyter基础操作2.1windows更新pip库2.2jupyter安装2.3初次启动jupyter2.
- 配置数据库密码特殊字符报错一般的springboot项目会有application.yml或者application.properties文
- 事务日志记录着在相关数据库上的操作,同时还存储数据库恢复(recovery)的相关信息。收缩日志的原因有很多种,有些是考虑空间不足,有些则是
- Python语法基础01-Python快速入门U1-定义变量直接定义 不用指明变量类型e.g:a=10U2-判断语句#coding=utf-
- 背景目前项目在移动端上,首推使用微信小程序。各项目的小程序访问数据有必要进行采集入库,方便后续做统计分析。虽然阿拉丁后台也提供了趋势分析等功
- 目录Java的数据库连接(JDBC)1、什么是JDBC2、JDBC的原理3、演示JDBC的使用4、数据库连接方式5、JDBC的查询6、SQL