trigger file upload dialog using javascript/jquery

后端 未结 5 1837
梦毁少年i
梦毁少年i 2020-12-01 07:39

instead of using , is it possible to use and then script it using javascript or jquery such

5条回答
  •  被撕碎了的回忆
    2020-12-01 08:18

    And if the HTML code has identical multiple inputs like this one below:-

    ​​​​​​​​​​​​​​​​​​​​​

    Expanding on @treeface's answer, the Jquery code (current version 1.8.0) would be:

    $('input[type=text]').click(function() {
        $(this).parent(".item")
            .find('input[type=file]')
            .trigger('click');
    });
    
    $('input[type=file]').change(function() {
        $(this).parent(".item")
            .find('input[type=text]')
            .val($(this).val());
    });​
    

    Do take note between $parents() and $parent() in jQuery. Try it out @ http://jsfiddle.net/afxDC/

提交回复
热议问题