input file “No File Choosen” text hide using button in jquery MultiFile

随声附和 提交于 2019-12-25 13:22:10

问题


I have following input file

<input type="file" id="sampleInput" name="files" onchange="return Plugins.sampleAction(this);"/>

In this file input I'm trying to remove "No File Choosen" text, for that I did following modification

<input type="file" id="sampleInput" name="files" onchange="return Plugins.sampleAction(this);" style='display:none'/>
 <button id="image_alt" type="button">Select image</button>

<script type="text/javascript">
    $('#image_alt').addEventListener('click', function () {
        $('#sampleInput').click();
    });
</script>

but when I click button this one not opening the file up-loader window


回答1:


You can try this

 $('#image_alt').on('click', function () {
        $('#sampleInput').click();
    });

addEventListener is the javascript way to listen for events, but you call it on a JQuery object. Give a look at JQuery.on() to manage events using JQuery.




回答2:


try this

<button id="image_alt" type="button">Select image</button>
  <p class="file_selected">File name</p>
<script type="text/javascript">
    $('#image_alt').on('click', function () {
        $('#sampleInput').click();
    });
    function changeVal(obj,cnt){
       $(cnt).text($(obj).val());
    }
</script>


来源:https://stackoverflow.com/questions/42466136/input-file-no-file-choosen-text-hide-using-button-in-jquery-multifile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!