当前位置: 首页 > news >正文

js 获取、清空 input type=file的值

上传控件(<input type="file"/>)用于在客户端浏览并上传文件,用户选取的路径可以由value属性获取,但value属性是只读的,不能通过 javascript来赋值,这就使得不能通过value=""语句来清空它。很容易理解为什么只读,如果可以随意赋值的话,那么用户只要打开你的网页, 你就可以随心所欲的上传他电脑上的文件了。

js 获取<intput type=file />的值

<html>

<script language='javascript'> 
function   show(){ 
var   p=document.getElementById("file1").value;
document.getElementById("s").innerHTML="<input id=pic type=image height=96 width=128 /> "; 
document.getElementById("pic").src=p;
alert(p);  

</script>


<head>
<title>MyHtml.html</title>

</head>

<body>
<input type="file" name="file1" id="file1" onpropertychange="show();" />
<span id="s"></span>

</body>


</html>


清空上传控件(<input type="file"/>)的值的两种方法

方法1:


<span   id=span1> 
<input   name=ab   type=file> 
</span> 
<input   name=button1   type=button   value="按"   οnclick=show()> 

<script   language=javascript> 
function   show() 

document.getElementById("span1").innerHTML="<input   name=ab   type=file>"; 

</script> 

方法2:
function clearFileInput(file){
var form=document.createElement('form');
document.body.appendChild(form);
//记住file在旧表单中的的位置
var pos=file.nextSibling;
form.appendChild(file);
form.reset();
pos.parentNode.insertBefore(file,pos);
document.body.removeChild(form);
}

相关文章:

  • 清空AsyncFileUpload 选择的文件路径
  • MySQL4.1导入的中文乱码问题
  • C#中string.Format的格式参数问题
  • Validation of viewstate MAC failed. 解决方法
  • ajaxpro组件在windows2008 + IIS7 下不能正常使用的问题
  • 解决Http Handler在IIS6与IIS7中的问题
  • 如何将aspx页面保存为utf-8格式
  • JavaScript判断浏览器类型及版本
  • SQL中CONVERT转化函数的用法
  • Access to the path is denied
  • (ckeditor+ckfinder用法)Jquery,js获取ckeditor值
  • jquery+ie6中的form无法提交问题
  • SQL Server由于登录失败而无法启动服务的解决方法
  • 找不到可安装的ISAM
  • importing excel to sql datetime is null
  • SegmentFault for Android 3.0 发布
  • 《深入 React 技术栈》
  • 【每日笔记】【Go学习笔记】2019-01-10 codis proxy处理流程
  • create-react-app项目添加less配置
  • Facebook AccountKit 接入的坑点
  • github指令
  • Intervention/image 图片处理扩展包的安装和使用
  • JAVA_NIO系列——Channel和Buffer详解
  • PHP 的 SAPI 是个什么东西
  • Phpstorm怎样批量删除空行?
  • Python学习之路13-记分
  • Spring Boot快速入门(一):Hello Spring Boot
  • 对超线程几个不同角度的解释
  • 构建工具 - 收藏集 - 掘金
  • 聊聊flink的TableFactory
  • 码农张的Bug人生 - 见面之礼
  • 免费小说阅读小程序
  • 那些年我们用过的显示性能指标
  • 前嗅ForeSpider教程:创建模板
  • 浅析微信支付:申请退款、退款回调接口、查询退款
  • 学习笔记TF060:图像语音结合,看图说话
  • 一个项目push到多个远程Git仓库
  • MiKTeX could not find the script engine ‘perl.exe‘ which is required to execute ‘latexmk‘.
  • MPAndroidChart 教程:Y轴 YAxis
  • Spring第一个helloWorld
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​Java并发新构件之Exchanger
  • #define、const、typedef的差别
  • $L^p$ 调和函数恒为零
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (二)基于wpr_simulation 的Ros机器人运动控制,gazebo仿真
  • (六)Hibernate的二级缓存
  • (强烈推荐)移动端音视频从零到上手(下)
  • (推荐)叮当——中文语音对话机器人
  • (一)appium-desktop定位元素原理
  • (转)3D模板阴影原理
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • .form文件_SSM框架文件上传篇