鍍金池/ 問答/HTML/ 這個if...else 條件為什么不成立?又不報錯!

這個if...else 條件為什么不成立?又不報錯!

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        header{
            width: 100%;
            position: fixed;
            top: 0;
        }
        .up{
            height: 55px;
            background-color: darkgreen;
            cursor: pointer;

        }
        .low{
            height: 60px;
            background-color: darkgray;
        }
        .ad{
            height: 340px;
            background-color: #3a945b;
            margin-top: 115px;
        }
        article{
            height: 1000px;
            background-color: orange;
        }
        footer
        {
            height: 320px;
            background-color: #1a1a1a;
        }
    </style>
    <script src="src/javascript/jquery-3.2.1.js"></script>
    <script>
        $(function () {
          var w = $('body').width();
          $('.up').click(function () {
            if(w>'1280px'){
              $('.low').animate({marginTop:200})
            }else{
              $('.low').animate({marginTop:50})
            }
          });
        });
    </script>
</head>
<body>
<header>
    <section class="up"></section>
    <section class="low"></section>
</header>
<div class="ad"></div>
<article></article>
<footer></footer>
</body>
</html>

if 沒作用,else可以?

回答
編輯回答
清夢

>只能進(jìn)行數(shù)值比較,1280px在這里是字符串,不能比較,所以條件觸發(fā)了else。

2017年8月8日 06:45
編輯回答
荒城

改成

if(w>1280)

圖片描述

2018年6月2日 09:57