Javascript 高度声明

标签 javascript css if-statement

这行不通,我不知道哪里出错了:

<style>
* {
margin: 0px
}  

div {
    height: 250px;
    width: 630px;
    overflow: hidden;
    vertical-align: top;
    position: relative;
}
  iframe {
    position: absolute;
    left: -50px;
    top: -130px;
  }
</style>
<script>
window.onload = function() {
   document.getElementsByTagName('body')[0].onkeyup = function(e) { 
      var div = document.getElementById('capture');
      if(e.keyCode == 70) {
         if(div.style.height == 250){
             alert("Yes");
         }
         else {alert("no");}
      }
   }
};
</script>

++++++++++++++编辑++++++++++++++

好的,这很好用:

         if(div.style.height < '260px'){
             alert("Yes!");
             div.style.height = '475px';
             pan.style.top = '-25';
         }
         else if(div.style.height > '260px') {
            alert("no");
            div.style.height = '250px';
            pan.style.top = '-130';
         }

但这不是:

     if(div.style.height = '250px'){
         alert("Yes!");
         div.style.height = '475px';
         pan.style.top = '-25';
     }
     else if(div.style.height = '475px') {
        alert("no");
        div.style.height = '250px';
        pan.style.top = '-130';
     }

什么给了?!?

最佳答案

div.style.height 返回 "250px" 字符串而不是 250 数字,所以你的 if(div.style. height == 250){ 不满足条件。

关于Javascript 高度声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4532878/

相关文章:

c# - 压缩 if-elseif-else 语句以节省比较

javascript - 在两个 div 之间移动 block

html - 想要在列表中的链接后面添加图像

html - 修复了向下滚动时标题图像被半透明图像覆盖的问题

html - 如何让这张响应式卡片变得更大?

python - 将命令添加到用户输入

javascript - 如何在 JavaScript 中获取数组特定索引处的值?

javascript - iOS 与安卓 : different dates displayed for the same program

javascript - 在自定义 React HOC 中获取 ownProps

Bash - "fi ;;"有什么用?