Javascript method to obtain the image path: 1. Use the getAttribute() function, the syntax is "image object.getAttribute('src')"; 2. Use the src attribute of the Image object
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In HTML, images are inserted through the src attribute of the img tag. The src attribute specifies the URL path to display the image.
Using javascript to obtain the image path is to use javascript to obtain the value of the src attribute of the img tag. Two methods are introduced below:
Method 1: Use the getAttribute() function
The getAttribute() method gets the value of the attribute by name.
Syntax:Picture object.getAttribute('src')
Example:
Output result:
Method 2: Use the src attribute of the Image object
Image object.src
javascript advanced tutorial]
The above is the detailed content of How to get the path of the image in javascript. For more information, please follow other related articles on the PHP Chinese website!