How to put background image inside textbox

前端 未结 5 709
后悔当初
后悔当初 2021-01-26 11:21

does anyone know how to put background image inside a textbox? i want to do is when i click the textbox it will change the background with an image.Does anyone know how to do th

5条回答
  •  一个人的身影
    2021-01-26 11:59

    To put a background image inside an input element you need to set background-image in CSS:

    input {
        background-image: url('image.png');
    }
    

    You can do it programmatically via JavaScript by adding/removing a class, or directly using this.style.backgroundImage. So here's an example:

    
    
    
    var i = document.getElementById('i');
    
    i.addEventListener('click', function() {
      i.style.backgroundImage = "url('image.png')";
    });
    

    Demo

提交回复
热议问题