How to change the width of a picture by javascript
Javascript how to change the width of the picture, in view of this question, this article introduces in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Methods: 1, use the "document.getElementById ('id value')" statement to get the picture object; 2, use the "picture object .setAttribute (" width "," width value ") or" picture object .style.width = "value" statement to change the width of the picture.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The method of changing the width of picture by javascript
1. Get the picture object according to the id value
Var img=document.getElementById ('img')
2. Use setAttribute ("width", "value") or the width property of the style object to change the width of the picture.
Img.setAttribute ("width", "width value"); / / or img.style.width = "width value"
Complete implementation code: