HTML+js+css实现点击图片弹出上传文件窗口的两种思路
2017-06-22 14:35
966 查看
第一种:CSS实现
<style>
<!--
.fileInputContainer{
height:256px;
background:url(upfile.png);
position:relative;
width: 256px;
}
.fileInput{
height:256px;
overflow: hidden;
font-size: 300px;
position:absolute;
right:0;
top:0;
opacity: 0;
filter:alpha(opacity=0);
cursor:pointer;
}
-->
</style>
<div class="fileInputContainer"><input class="fileInput" id="" type="file" name=""></div>
第二种:JavaScript实现
<div class="face">
<p><img class="normalFace" src="./images/upload.jpg" onclick="fileSelect();"></p>
<form id="form_face" enctype="multipart/form-data" style="width:auto;">
<input type="file" name="fileToUpload" id="fileToUpload" onchange="fileSelected();" style="display:none;">
</form>
</div>
<script type="text/javascript">
function fileSelect() {
document.getElementById("fileToUpload").click();
}
function fileSelected() {
// 文件选择后触发次函数
}
</script>
<style>
<!--
.fileInputContainer{
height:256px;
background:url(upfile.png);
position:relative;
width: 256px;
}
.fileInput{
height:256px;
overflow: hidden;
font-size: 300px;
position:absolute;
right:0;
top:0;
opacity: 0;
filter:alpha(opacity=0);
cursor:pointer;
}
-->
</style>
<div class="fileInputContainer"><input class="fileInput" id="" type="file" name=""></div>
第二种:JavaScript实现
<div class="face">
<p><img class="normalFace" src="./images/upload.jpg" onclick="fileSelect();"></p>
<form id="form_face" enctype="multipart/form-data" style="width:auto;">
<input type="file" name="fileToUpload" id="fileToUpload" onchange="fileSelected();" style="display:none;">
</form>
</div>
<script type="text/javascript">
function fileSelect() {
document.getElementById("fileToUpload").click();
}
function fileSelected() {
// 文件选择后触发次函数
}
</script>
相关文章推荐
- HTML+js+css实现点击图片弹出上传文件窗口的两种思路
- HTML+js+css实现点击图片弹出上传文件窗口的两种思路
- HTML+js+css实现点击图片弹出上传文件窗口的两种思路
- HTML+js+css实现点击图片弹出上传文件窗口的两种思路
- HTML+js+css实现点击图片弹出上传文件窗口的两种思路
- JS实现点击某张图片弹出上传图片窗口以及限制图片格式和大小
- js实现点击按钮弹出上传文件的窗口
- js实现点击按钮弹出上传文件的窗口
- js实现点击按钮弹出上传文件的窗口
- Web实现点击图片弹出上传文件窗口
- js实现点击按钮弹出上传文件的窗口
- JS点击图片弹出文件选择框并覆盖原图功能的实现代码
- jsp中点击图片弹出文件上传界面及实现预览
- .NET, MVC框架下利用html, CSS,js实现弹出窗口
- webuploader+springmvc实现多文件上传(html+js+css原创,后台代码借鉴)
- jsp中点击图片弹出文件上传界面及实现预览实例详解
- js弹出窗口实现动态文件上传
- html 点击文字或图片弹出上传文件对话框
- .NET, MVC框架下利用html, CSS,js实现弹出窗口
- .NET, MVC框架下利用html, CSS,js实现弹出窗口