出于安全方面的考虑,通过JS修改input-file的value是无法正确上传文件的。
只有当鼠标真正单击在上传控件的浏览按钮所添加的文件才可以上传。
使用按钮触发input-file需要通过模拟实现。
方法是:在button上方添加浮动的file控件,使用户点击button时,实际上点击file控件的按钮。
这个方法需要浏览器支持滤镜效果。
<html>
<head>
<title>添加附件</title>
</head>
<body class="body">
<script type="text/javascript">
function fclick(obj){
obj.style.posTop=event.srcElement.offsetTop
var x=event.x-obj.offsetWidth/2
if(x<event.srcElement.offsetLeft)x=event.srcElement.offsetLeft
if(x>event.srcElement.offsetLeft+event.srcElement.offsetWidth-obj.offsetWidth)x=event.srcElement.offsetLeft+event.srcElement.offsetWidth-obj.offsetWidth
obj.style.posLeft=x
}
</script>
<style>
input{border:1px solid #333333;color:#666666;background:#eeeeee;font:normal 12px Tahoma;height:18px}
</style>
<form method="post" action="" enctype="multipart/form-data">
<input id="f_file" type='text'>
<input type="button" onmouseover="fclick(t_file)" value="选择上传文件">
<input name="upload" type="file" style="position:absolute;filter:alpha(opacity=20);width:30px;" id="t_file" onchange="f_file.value=this.value" hidefocus>
<!-- opacity是透明度 这里写20是为了方便浏览,使用时应设置为0 -->
<input type="submit" value="提交">
</form>
</body>
</html>
分享到:
相关推荐
window.createObjectURL 上传图片,实现web预览
表单控件-Input控件 表单控件 学习表单的核心就是学习表单控件,HTML语言提供了一系列的表单控件,用于定义不同的表单功能,如密码输入框、文本域、下拉列表、复选框等。 表单控件 表单控件常用在登录和注册模块 ...
voice-input-button2New version of voice input button using new interface of iflytek voice dictation (the stream version).基于讯飞新版语音听写(流式版) api 的语音输入按钮 vue 组件。使用 HTML 原生媒体...
6、Button 控件 7 7、GroupBox 控件 7 8、RadioButton控件 8 9、CheckBox 控件 8 10、ListBox 控件 9 11、ComboBox 控件 10 12、CheckedListBox 控件 10 13、PictureBox 控件的使用 11 14、Timer 控件 11 15、...
在VS2010 MFC下实现radio-button和check-button的联合使用,可以运行
html修改FileUpload控件的浏览按钮的文字改为自定义
Button控件 滑块控件 分段控件 工具栏
这篇文章主要介绍了微信小程序button标签open-type属性原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 open-type (微信开放能力):合法值中的其中之一...
Swift 几个简单控件 以及 上传系统相册照片
在系统给的button控件基础上做一个控件,继承Button控件,自定义新的Button控件,简单APP源码,
Button控件 的简单使用(button监听和onClick触发函数使用) 具体可参考我文章。https://mp.csdn.net/postedit/84561464 【更新-->下载所需积分太高,更改为固定分值了】
bower install angular-file-model --save 添加到您HTML文件中: [removed][removed] 现在,注入您的应用程序: angular.module('myApp', ['file-model']); 准备在您的控制器中使用!: file.html : <input...
六、Button 控件 - 7 - 七、GroupBox 控件 - 8 - 八、RadioButton控件 - 8 - 九、CheckBox 控件 - 8 - 十、ListBox 控件 - 9 - 十一、ComboBox 控件 - 11 - 十二、CheckedListBox 控件 - 11 - 十三、PictureBox 控件...
grafana button panel
react-stl-file-viewer 安装 npm install --save react-stl-file-viewer 用法 import React , { useState } from 'react' import { StlViewer } from 'react-stl-file-viewer' import { Box , Button , Flex , ...
智能家居系统应用
input type=button value=上传文件 name= id= @click=updata> <input type=file style=display:none @change=getFile id=input-file> <div v-if=fileName> 上传的文件名:{{fileName}}</p>
这里简单介绍一下如何在android中触发加载的html界面的Button控件。 1. 首先看Activity的代码: 首先我们要获取到当前的WebView控件,然后通过html的路径加载html界面,当前的html路径我是在本地的,然后设置 ...
fileDesc : 这个属性值必须设置fileExt属性后才有效,用来设置选择文件对话框中的提示文本,如设置fileDesc为“请选择rar doc pdf文件”,打开文件选择框效果如下图: fileExt : 设置可以选择的文件的类型,...
Qt4下的自定义Button控件源码,将生成的.so控件库,拷贝到QtDesigner目录下,在QtDesignerIDE开发环境中就可以看到Button控件