html点击button弹出选择文件,上传,这个怎么实现?

就类似这样

这个样式挺漂亮的,你可以试下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义input type="file" 的样式</title>
<style type="text/css">
body{ font-size:14px;}
input{ vertical-align:middle; margin:0; padding:0}
.file-box{ position:relative;width:340px}
.txt{ height:22px; border:1px solid #cdcdcd; width:180px;}
.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;}
.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px }
</style>
</head>
<body>
<div class="file-box">
<form action="" method="post" enctype="multipart/form-data">
<input type='text' name='textfield' id='textfield' class='txt' />
<input type='button' class='btn' value='浏览...' />
<input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" />
<input type="submit" name="submit" class="btn" value="上传" />
</form>
</div>
</body>
</html>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-29
把HTML的input元素设置type为file即可,类似这样:
<input type="file" name="uploadfile" id="uploadfile" value="Browse..." />
第2个回答  2019-01-28
    <div class="button operating-button" id="fileUpdate-button">从Excel中批量导入</div>
<form action="" id ="fileUpdate-form">
    <input type="file" name="filename" id="fileUpdate-input" style="display: none" />
</form>
<script type="text/javascript">
    //上传文件处理
    var fileUpdate_button = document.getElementById("fileUpdate-button");
    var fileUpdate_input = document.getElementById("fileUpdate-input");
    var fileUpdate_form = document.getElementById("fileUpdate-form");
    fileUpdate_button.onclick = function () {
        fileUpdate_input.click();
    }
    fileUpdate_input.onchange = function () {
        fileUpdate_form.submit();
    }
</script>

第3个回答  2018-01-06
<form action="" method="post" enctype="multipart/form-data">

<input type='file' name='textfield' id='textfield' />
<input type='button' value='浏览...' />
<input type="file" name="fileField" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" />
<input type="submit" name="submit" value="上传" />
</form>
其中样式在分别给每一个表单元素自定义class!
第4个回答  2013-10-29
用swfupload

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网