file input javascript click generated not from a real mouse click chrome

前端 未结 2 1802
栀梦
栀梦 2020-12-20 08:07

i\'m having trouble in chrome opening the popup for the file upload of a file input type.

As you can see here: http://jsfiddle.net/cavax/K99gg/3/, clicking on an ele

2条回答
  •  时光取名叫无心
    2020-12-20 08:39

    There is no way to trigger click event of input file type, because of a security reason.

    You may try a hack of this by setting your button/div position to absolute and top to -100px It means positioning it outside the viewport by setting above style make it works.

    But for mouseenter and mouseover i don't think it's going to work!

    Edit:

    Moved input outside the viewport and target click event

    Example on click

    Side note: Right now click occurs 2 times as you have written

    $('#upload').trigger('click').click();
    

    You just need

    $('#upload').trigger('click');  //  $('#upload').click() 
    

    unless you want it to fire more than single time.

提交回复
热议问题