jQuery CSS 方法获取不带单位的属性值?
1, 首先定义一个 div
<div></div>
2, 然后设置样式 (相关课程推荐: jQuery 教程 https://www.html.cn/jskuangjia/jquery/ )
- <style>
- div {
- width: 100px;
- height: 100px;
- }
- </style>
3, 引入 jQuery
<script src="path/to/jquery.min.js"></script>
4, 使用 jQuery 的 CSS 方法获取元素的宽度
- var h = $('div').CSS('width');
- console.log(h); //100px
5, 获取的值是带单位的, 使用 parseInt 方法去除单位即可
- var nopx = parseInt(h);
- console.log(nopx);//100
来源: http://www.css88.com/qa/jquery/16092.html