[英]jQuery child file upload click
I tried to run the code as and its working 我试图将代码作为及其运行
<input type="file" />
<div class="image">
</div>
$('.image').click(function() {
$('input').trigger('click');
});
Now, I want the code as 现在,我希望代码为
<div class="image">
<input type="file" />
</div>
$('.image').click(function() {
$(this).find('input').trigger('click');
});
and, I am not sure why this is not working. 而且,我不确定为什么这不起作用。
Sample Fiddle is here. 示例小提琴在这里。 http://jsfiddle.net/CSvjw/1538/
http://jsfiddle.net/CSvjw/1538/
Problem is: 问题是:
Solution: 解:
$('.image').click(function(event) { if (!$(event.target).is('input')) { $(this).find('input').trigger('click'); } });
input[type=file] { display: none; height: 0; width: 0; } .image { height: 100px; width: 100px; background-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="image"> <input type="file" /> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.