代码在IE中工作,但在任何其他浏览器中都没有,不知道为什么

时间:2018-05-29 09:30:21

标签: html

我有新编程和网络编程,这段代码假设显示我选择的图片的日期和时间,并随着时间和日期的变化而相应地改变,代码工作并在IE中正确显示图像但不是在FireFox Chrome或任何其他浏览器上,在其他浏览器上显示图片但不遵循样式规则,因为编码是我的代码有问题或者我错过了其他东西

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
 image{
       posyion: fixed;
       width: 120px;
       max-width: 100%;
       height:300px;
       max-height:100%; 
       overflow: visible;
       margin: auto;
       padding: 0;
     } 

</style>
<script>
function startTime() {
  var today = new Date();
  var h = today.getHours();
  var m = today.getMinutes();
  var s = today.getSeconds();
  var yyyy = today.getFullYear();
  var mm = today.getMonth() + 1; 
  var dd = today.getDate();
  h = checkTime(h);
  m = checkTime(m);
  s = checkTime(s);
  mm = ( mm < 10 ) ? ( "0" + ( mm ).toString() ) : ( mm 
  ).toString();
  dd = ( dd < 10 ) ? ( "0" + ( dd ).toString() ) : ( dd 
  ).toString()

  var string = h + ":" + m + ":" + s ;
  var string1 =  dd + "-" + mm + "-" + yyyy;

  var img = stringToImage(string);
  var img2 = stringToImage(string1);


   document.getElementById('timetxt').innerHTML = img;
   document.getElementById('timetxt2').innerHTML = img2;

   var t = setTimeout(startTime, 500);
 }
 function checkTime(i) {
   if (i < 10) {
     i = "0" + i
 } 
   return i;
}

function stringToImage(s) {
   var temp = ""
   for (var i = 0; i < s.length; i++) {

    temp = temp + "<img src='" + img[s[i]] + "'/>"
  }
  return temp
}


var img = {
            "1": "images/one.jpg",
            "2": "images/two.png",
            "3": "images/three.jpg",
            "4": "images/four.jpg",
            "5": "images/five.jpg",
            "6": "images/six.png",
            "7": "images/seven.jpg",
            "8": "images/eight.png",
            "9": "images/nine.jpg",
            "0": "images/zero.gif",
            ":": "images/Colon.jpg",
            "-": "images/line.jpg"
      }

</script>

</head>

<body onload="startTime()">
<div id="container" align = "center">
<div id="timetxt" class = "image" align = "center"></div>
<div id="timetxt2" class = "image" align = "center"></div>
</div>

</body>
</html>

所有图片都显示在所有浏览器上,但仅在IE上应用样式参数,因此图片的宽度应为180px,高度为300px,因此IE浏览器应用这些规则,但其他浏览器不适用这些规则规则似乎只发生在代码的样式部分,其他一切按计划运行

1 个答案:

答案 0 :(得分:1)

我立刻注意到你有posyion代替position,而你正试图声明你的图片是position: fixed

我不知道这是否是你遇到的唯一问题,但这会搞得很多。