Is it possible to change img src attribute using css?

后端 未结 9 821
旧巷少年郎
旧巷少年郎 2021-01-07 23:20

I\'m trying to change img src (not the background img src) with css

\"btnUp\"/  

#btnUp{
    cursor:poi         


        
9条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-07 23:38

    You can use a mixture of JavaScript and CSS to achieve this, but you can not do this with CSS alone. btnUp Instead of img you would put file name sans file type.

    function change(img){
    document.getElementById("btnUp").src= img + ".png";
    }
    function changeback(img){
    document.getElementById("btnUp").src= img + ".png";
    }
    

    Then you use CSS to modify the img tag or the id to your liking.

提交回复
热议问题