【问题标题】:jquery way to get property value inside style attribute when property key exist?当属性键存在时,jquery方法在样式属性中获取属性值?
【发布时间】:2012-06-23 14:03:16
【问题描述】:
<div class="test" style="position:absolute; font-size: 12; right:400px; top:100px;"><p>Hello</p></div>
<div class="test" style="position:absolute; font-size: 14; right:200px; top:140px;"><p>Hello</p></div>

我想做类似的事情

var positionvalue= $('.test'). get value where position is exist inside style attribute  
var topvalue= $('.test'). get value where top is exist inside style attribute.

有没有什么简单的方法可以通过 jquery 来实现呢?

意思是不需要将样式读入变量,然后拆分为数组数组,循环通过比较属性键来获取值。

【问题讨论】:

    标签: jquery properties styles inline


    【解决方案1】:

    要获得 Top,请使用此

    $('.test').position().top
    

    示例:返回 100

    要获得位置,请使用此

    $('.test').css('position')
    

    示例:返回绝对

    参考LIVE DEMO

    【讨论】:

      【解决方案2】:

      这里是JQuery APIposition()的链接

      如上所述,您的代码将是:-

      var topvalue= $('.test').position.top;
      

      【讨论】:

        猜你喜欢
        • 2016-03-04
        • 1970-01-01
        • 2011-05-25
        • 2019-10-26
        • 2014-10-27
        • 1970-01-01
        • 2011-11-02
        • 2023-03-22
        • 2013-03-20
        相关资源
        最近更新 更多