JS缩小图片的方法:1、使用setAttribute()方法,语法“图片对象.setAttribute("width", "更小的宽度值")”。2、使用style对象的width属性,语法“图片对象.style.width="更小的值"”。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
JavaScript中缩小图片的方法
方法1:使用setAttribute()
@@##@@<br /><br /> <button onclick="myFunction()">缩小图片</button> <script type="text/javascript"> function myFunction() { document.getElementById('img').setAttribute("width", "300"); } </script>
输出结果:
立即学习“Java免费学习笔记(深入)”;
方法2:使用style对象的width属性
@@##@@<br /><br /> <button onclick="myFunction()">缩小图片</button> <script type="text/javascript"> function myFunction() { document.getElementById('img').style.width="300px"; } </script>
输出结果:
立即学习“Java免费学习笔记(深入)”;
【推荐学习:javascript高级教程】
以上就是JavaScript中怎么缩小图片的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号