【发布时间】:2013-04-26 10:38:43
【问题描述】:
我正在尝试使用我的自定义样式创建一个 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>
【问题讨论】:
-
现在正在触发点击,但标签文本没有填满。 $("button").click(function() { var $this = $(this), inputVal = $this.prev().val(); //$this.prev().trigger('click') ; $this.prev().trigger('click', function(){ $(this).change(function(){ $this.next().text(inputVal); }); } ); });
标签: jquery forms file-upload input