javascript - jQuery 的attr( )方法为什么不能获取 <input type="button" />的宽高?
本文介绍了javascript - jQuery 的attr( )方法为什么不能获取 <input type="button" />的宽高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
</script>
<style type="text/css">
input{width:100px;height:70px;color: red;background-color: azure;}
</style>
<script type="text/javascript">
$(function() {
$("input").click(function() {
alert($("input").attr("width","height"));
})
})
</script>
</head>
<body>
<input type="button" value="显示"/>
</body>
解决方案
你需要看看官方文档。
$(function() {
$("input").click(function() {
alert($(this).height() + 'px:' + $(this).width() + 'px');
})
})
attr的用法:
http://www.css88.com/jqapi-1.9/attr/
height:
http://www.css88.com/jqapi-1.9/height/
prop:
http://www.css88.com/jqapi-1.9/prop/
这篇关于javascript - jQuery 的attr( )方法为什么不能获取 <input type="button" />的宽高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文