Skip to content

Instantly share code, notes, and snippets.

@ShigeoTejima
Created February 6, 2017 22:37
Show Gist options
  • Save ShigeoTejima/3bdb80d8e95689282f7ed5f8b162173f to your computer and use it in GitHub Desktop.
Save ShigeoTejima/3bdb80d8e95689282f7ed5f8b162173f to your computer and use it in GitHub Desktop.
on ie9, desined input[type=file] sample.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Test</title>
<script src="js/jquery-3.1.1.min.js"></script>
<style>
.file-container {
display: inline-block;
overflow: hidden;
position: relative;
padding: .5em;
}
.file-container input[type="file"] {
opacity: 0;
position: absolute;
right: 0;
top: 0;
margin: 0;
font-size: 100px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Hello, world!</h1>
<form name="form" action="test.html" method="post" enctype="multipart/form-data">
<div class="file-container">
<input type="file" id="file" name="file" class="file">
<button type="button" name="btnsubmit">Fileupload</button>
</div>
</form>
</div>
<script>
$(function() {
$("input[type=file][name=file]").on("change", function() {
var $this = $(this);
console.log("changed -> " + $this.val());
if ($this.val()) {
$this.closest("form").submit();
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment