1、Jquery获取控件的坐标位置
//offset()获取当前元素基于浏览的位置
var left = $("selector").offset().left;//元素相当于窗口的左边的偏移量
var top = $("selector").offset().top;//元素相对于窗口的上边的偏移量
//
var pleft = $("selector").scrollLeft();//元素相对于滚动条左边的偏移量
var pTop = $("selector").scrollTop();//元素相对于滚动条顶部的偏移量
//position()获取当前元素基于父容器的位置
var positiontop=$("#id").position().top;
var positionleft=$("#id").position().left;
//设置id2的位置基于unamespan的坐标
$("#id2").css({position: "absolute",'top':offsettop+100,'left':offsetleft+50,'z-index':2});
2、使用jquery修改css中带有!important的样式属性
<div class="test">使用jquery修改css中带有!important的样式属性</div>
外部样式为
div.test{
width:100px !important;
overflow:100px !important;
}
通过$("div.test").css("width","400px");和 $("div.test").css("width","400px !important");
要想修改,可通过如下方式:
$("div.test").css("cssText", "width:650px !important;");
要想修改多个属性,可通过如下方式:
$("div.test").css("cssText", "width:650px !important;overflow:hidden !important");
3、综合例子
.css
#topPopover {
width: 90%;
height: 1.8rem;
top: 45% !important;
}
js中
var topvalue = $("#pwdDiv").offset().top;
$("#topPopover").css("cssText", "top:"+topvalue+"px !important;"); //修改CSS