How do I add a Font Awesome icon to file input field

前端 未结 3 2025
Happy的楠姐
Happy的楠姐 2021-02-04 21:26

I have a file input button, instead of browse I want to show Font Awesome upload icon there but whatever I tried nothing gave me result.

Here is what I\'ve tried

3条回答
  •  梦谈多话
    2021-02-04 22:26

    You could hide file input with display: none and create custom button or in this case font-awesome icon that will trigger input. Also you can use span to display input's value that will change on input value change.

    $("i").click(function () {
      $("input[type='file']").trigger('click');
    });
    
    $('input[type="file"]').on('change', function() {
      var val = $(this).val();
      $(this).siblings('span').text(val);
    })
    .element {
      display: inline-flex;
      align-items: center;
    }
    i.fa-camera {
      margin: 10px;
      cursor: pointer;
      font-size: 30px;
    }
    i:hover {
      opacity: 0.6;
    }
    input {
      display: none;
    }
    
    
    
    No file selected

提交回复
热议问题