码迷,mamicode.com
首页 > Web开发 > 详细

jQuery的位置信息

时间:2018-06-04 18:23:49      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:this   convert   fun   使用   ace   对象   span   his   TE   

jQuery的位置信息跟JS的client系列、offset系列、scroll系列封装好的一些简便api.

 

一、宽度和高度

获取宽度

.width()

描述:为匹配的元素集合中获取第一个元素的当前计算宽度值。这个方法不接受任何参数。.css(width) 和 .width()之间的区别是后者返回一个没有单位的数值(例如,400),前者是返回带有完整单位的字符串(例如,400px)。当一个元素的宽度需要数学计算的时候推荐使用.width() 方法 。

设置宽度

.width( value )

描述:给每个匹配的元素设置CSS宽度。

 

          console.log($(‘.box‘).width());
            console.log($(‘.box2‘).width())
            console.log($(‘.box‘).css(‘width‘));//这样打印出来的是带有px的 不便于我们进行 操作
            $("<a>年后</a>").insertAfter($(‘button‘));
            $(‘button‘).eq(0).click(function(){
                console.log($(this).next());//获取下一个的对象
                console.log($(this).height());
                $(this).height(30); //设置高度
                console.log($(this).height());

 

jQuery的位置信息

标签:this   convert   fun   使用   ace   对象   span   his   TE   

原文地址:https://www.cnblogs.com/askzyl/p/9134735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!