Css:jquery中的margin-left值检查

时间:2016-08-30 14:55:35

标签: jquery

我试图检查边距 - 左边。但它不起作用。谢谢提前

 if( $car1.css("margin-left") == "1060px") {
   $("#result").html("Car One Won The Race!!");     
 }

1 个答案:

答案 0 :(得分:0)

.css("margin-left")更改为.css("marginLeft")

喜欢这个:

$(document).ready(function(){

    if ($car1.css("marginLeft") == "1060px")

        $("#result").html("Car One Won The Race!!"); 

})

最终代码:



<html>
    <title>This is test</title>
    
    <head>
        <style>
            div {
                margin-left: 1060px;
            }
        </style>
    </head>
    <body>
        
        <div>I am div, and margin_left 1060px</div>
        <p id="result"></p>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script>
            
        $(document).ready(function(){
            $car1 = $("div");
            if ($car1.css("marginLeft") == "1060px")

                $("#result").html("Car One Won The Race!!"); 

        })
        </script>
    </body>
</html>
&#13;
&#13;
&#13;