选择和图像形成图像串并将其放置在正确的时间关闭和打开

时间:2017-07-23 09:04:56

标签: javascript html

我试图创建一个图像串,因为这两个图像将被频繁共享,但它只显示网址而不是图像。 ti将使用时间告诉同一页面中的不同内容。但我的问题是。我正确放置字符串名称吗? timeDiv4.innerHTML ='它' s' +今天+' ' +小时+':' +分钟+后缀+'
' + imgArray [0 \ 1] .src; 还是我需要其他任何东西



//////////////////End Modal 3////////////
var imgArray = new Array();

imgArray[0] = new Image(100,100);
imgArray[0].src = 'http://www.weebly.com/editor/uploads/1/1/3/4/11341626/custom_themes/599346900698327146/files/Gifs/OpenLightOff.png';

imgArray[1] = new Image(100,100);
imgArray[1].src = 'http://www.weebly.com/editor/uploads/1/1/3/4/11341626/custom_themes/599346900698327146/files/Gifs/OpenLightOn.gif';


var now = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";     
weekday[1] = "Monday";     
weekday[2] = "Tuesday";     
weekday[3] = "Wednesday";   
weekday[4] = "Thursday";   
weekday[5] = "Friday";      
weekday[6] = "Saturday";    	

//////////Highlights the date/////

//10:00 am - 10:00 pm  
//10:00 am - 10:00 pm
//10:00 am - 10:00 pm
//10:00 am - 10:00 pm
//10:00 am - 10:00 pm
//10:00 am - 10:00 pm
//10:00 am - 10:00 pm

var checkTime4 = function() {
  var today = weekday[now.getDay()];
  var timeDiv4 = document.getElementById('timeDiv4');
  var timeBorder4 = document.getElementById('timeBorder4');

  
  var dayOfWeek = now.getDay();
  var hour = now.getHours();
  var minutes = now.getMinutes();

  //add AM or PM
  var suffix = hour >= 12 ? "PM" : "AM";
  

  // add 0 to one digit minutes
  if (minutes < 10) {
    minutes = "0" + minutes
  };

  if ((dayOfWeek == 0 || dayOfWeek == 1 || dayOfWeek == 2 || dayOfWeek == 3 || dayOfWeek == 4 ) && hour >= 10 && hour <= 21) {
    hour = ((hour + 11) % 12 + 1); //i.e. show 1:15 instead of 13:15
	timeDiv4.innerHTML = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + imgArray[1].src  ;
    timeDiv4.className = 'open';
	timeBorder4.className = 'OpenGreen';

  } 
  
  else if ((dayOfWeek == 5 || dayOfWeek == 6) && hour >= 10 && hour <= 22) {
    hour = ((hour + 11) % 12 + 1);
    timeDiv4.innerHTML = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + imgArray[1].src  ;
    timeDiv4.className = 'open';
	timeBorder4.className = 'OpenGreen';

  } 
  
  else {
    if (hour == 0 || hour > 9) {
      hour = ((hour + 11) % 12 + 1); //i.e. show 1:15 instead of 13:15
    }
    timeDiv4.innerHTML = 'It\'s ' + today + ' ' + hour + ':' + minutes + suffix + '<br>' + imgArray[0].src  ;
    timeDiv4.className = 'closed';
	timeBorder4.className = 'ClosedRed';

  }
};

setInterval(checkTime4, 1000);
checkTime4();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<div id="timeDiv4"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您需要添加HTML标记 - 如下所示:

timeDiv4.innerHTML = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + '<img src = ' + imgArray[1].src + '>'  ;