html点击button弹出选择文件,上传,这个怎么实现
推荐于2018-11-17
<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!
<div class="button operating-button" id="fileUpdate-button">上传文件</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>
<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!