javascript - Uncaught RangeError: Maximum call stack size exceeded (multiple input=file ) - Stack Overflow

HTML<div class="event-image"><figure><img src="<?php echo base_url(�

HTML

<div class="event-image">
  <figure>
    <img src="<?php echo base_url('assets/images/addimg.png'); ?>" />
    <figcaption class="imagcaption">Add Image</figcaption>
  </figure>
  <input type="file" name="upload" />
</div>

jQuery

$(document).on("click","div.event-image",function(){
    $(this).children("input[type=file]").trigger("click");    
});

I create above div in loop, so there will me many divs with class="event-image". How to trigger the file of the div on which the user click.

Any help would be great

HTML

<div class="event-image">
  <figure>
    <img src="<?php echo base_url('assets/images/addimg.png'); ?>" />
    <figcaption class="imagcaption">Add Image</figcaption>
  </figure>
  <input type="file" name="upload" />
</div>

jQuery

$(document).on("click","div.event-image",function(){
    $(this).children("input[type=file]").trigger("click");    
});

I create above div in loop, so there will me many divs with class="event-image". How to trigger the file of the div on which the user click.

Any help would be great

Share Improve this question edited Dec 1, 2015 at 7:15 Rajesh 25k5 gold badges50 silver badges83 bronze badges asked Dec 1, 2015 at 7:09 Waqar HaiderWaqar Haider 9731 gold badge10 silver badges34 bronze badges 3
  • 2 Because when you triggering input click on document click. Document click automatically calling again and it repeating this process. So you getting this error. – Manwal Commented Dec 1, 2015 at 7:14
  • You can use e.stopPropagation() inside click of file – Rajesh Commented Dec 1, 2015 at 7:16
  • i am calling document bcz its ajax uploaded div and without it i am not able to click on it – Waqar Haider Commented Dec 1, 2015 at 7:16
Add a ment  | 

1 Answer 1

Reset to default 8

Use e.stopPropagation()

Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

Add this:

$("input[type=file]").on("click", function(e){
   e.stopPropagation();
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742342989a4425997.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信