我试图用我的自定义样式创建一个 FORM 文件输入按钮。
下面是代码,但它不起作用。
<style type="text/css">
.pictures { width:200px; height:70px; overflow:hidden;}
input{position:absolute; top:-100px;}
</style>
<form id="test_form" method="post">
<div class="pictures">
<input type="file">
<button>Upload</button>
<label>No file selected</label>
</div>
<div class="pictures">
<input type="file">
<button>Upload</button>
<label>No file selected</label>
</div>
<div class="pictures">
<input type="file">
<button>Upload</button>
<label>No file selected</label>
</div>
</form>
<script>
$(function(){
$("button").click(function() {
var $this = $(this),
inputVal = $this.closest('input').val();
$this.closest('input').click(
function(){
$(this).change(function(){
$this.closest('label').text(inputVal);
});
}
);
})
});
</script>