Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the width of a picture by javascript

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report