当我点击文件浏览器按钮时没有点击提交,它已经提交了表单?如何在 IE 11/IE Edge 中防止它(所有其他浏览器都可以处理)。
CSS:
.upload-btn-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
}
.btn {
border: 2px solid gray;
color: gray;
background-color: white;
padding: 8px 20px;
border-radius: 8px;
font-size: 20px;
font-weight: bold;
}
.upload-btn-wrapper input[type=file] {
font-size: 100px;
position: absolute;
left: 0;
top: 0;
opacity: 0;
}
html:
<form method="post" action="test.php" enctype="multipart/form-data" id="form1" name="form1">
<div class="upload-btn-wrapper">
<button class="btn">upload file</button>
<input type="file" class="form-control"
placeholder="" id='files' name='files' onchange="files(this);"/>
</div>
JS:
function files(elm) {
var fn = $(elm).val();
var filename = fn.match(/[^\\/]*$/)[0];
//$('#selected_filename').html(filename);
}