扫码关注官方订阅号
认证高级PHP讲师
谢谢邀请。使用width()/height()即可。attr()是取值或赋值用的。
width()
height()
attr()
var _w = $('input[type="button"]').width(), _h = $('input[type="button"]').height(); console.log('width:'+_w+' height:'+_h);
$("input").width()$("input").height()
$("input").css("width")$("input").css("height")
你代码的问题有2,
宽高是css属性
attr("width","height") 这是赋值的写法, 并不是同时获取width和height
建议你看看jq手册的attr方法,看看它的介绍,看完你就明白了
attr是attribute的缩写,而attribute的意思是属性
attr.width()
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
谢谢邀请。使用
width()/height()即可。attr()是取值或赋值用的。$("input").width()
$("input").height()
$("input").css("width")
$("input").css("height")
你代码的问题有2,
宽高是css属性
attr("width","height") 这是赋值的写法, 并不是同时获取width和height
建议你看看jq手册的attr方法,看看它的介绍,看完你就明白了
attr是attribute的缩写,而attribute的意思是属性
attr.width()