最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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();
})
发布评论

评论列表(0)

  1. 暂无评论