Styling an input type=“file” button

后端 未结 30 1655
终归单人心
终归单人心 2020-11-21 11:50

How do you style an input type=\"file\" button?

30条回答
  •  灰色年华
    2020-11-21 12:11

    The best way I have found is having an input type: file then setting it to display: none. Give it an id. Create a button or any other element you want to open the file input.

    Then add an event listener on it (button) which when clicked simulates a click on the original file input. Like clicking a button named hello but it opens a file window.

    Example code

    //i am using semantic ui
    
    
      
    

    javascript

    var attachButton=document.querySelector('.attach-button');
        attachButton.addEventListener('click', e=>{
            $('#file').trigger("click")
        })
    

提交回复
热议问题