Javascript gets the url value in the background attribute, and js gets the backgroundurl
Preface
Recently, when I was working on a project, I encountered a problem. I needed to obtain the address of a dynamic preview image. This is not a problem. The path of the image is mainly written in css.Background-img
Attribute, so I decided to use js to get the content in its url. I will share with you the solution below. If you need it, let's take a look.
Var avatar = $ ("# image-preview" ).css ("backgroundImage"); alert (avatar );
Obtain includeUrl(“xxx.jpg ")
Format value, so I checked the information and found to only getXxx.jpg
Method of form value:
Var avatar = $ ("# image-preview" ).css ("backgroundImage"); avatar = avatar. split ("(") [1]. split (")") [0]; alert (avatar );
The obtained value is the image address.
Summary
The above is all about this article. I hope the methods shared in this article will be helpful for you to learn or use Javascript. If you have any questions, please leave a message.