Quantcast
Channel: iT邦幫忙
Viewing all articles
Browse latest Browse all 15645

問一下這段javascript程式碼輸出如何顯示呢?

$
0
0
<!doctype html><html lang="en"><head><title>Movielist</title><meta charset="utf-8"><script>
		window.onload=function getNextShowing(movie)
{
	var now = new Date().getTime();
	for(var i=0; i < movie.showtimes.length; i++)
	{
		var showtime = getTimeFromString(movie.showtimes[i]);
		if((showtime - now ) > 0)
		{
			return "Next showing of"+movie.title+" is "+movie.showtimes[i];
		}
	}
	return null;
}

function getTimeFromString(timeString)
{
	var theTime = new Date();
	var time = timeString.match(/(\d+)(?::(\d\d))?\s*(p?)/);
	theTime.setHours(parseInt(time[1]) + (time[3] ? 12 : 0));
	theTime.setMinutes(parseInt(time[2]) || 0);
	return theTime.getTime;
}

var movie1=
{
	title:"Plan 9 from Outer Space",
	genre:"Cult Classic",
	rating:5,
	showtimes:["3:00pm","7:00pm","11:00pm"]
};

var movie2=
{
	title:"Forbidden Planet",
	genre:"Classic Sci-fi",
	rating:5,
	showtimes:["5:00pm","9:00pm"]
};


var nextShowing = getNextShowing(movie1);
alert(nextShowing);
nextShowing = getNextShowing(movie2);
alert(nextShowing);

		</script></head><body></body></html>


這段主要是把movie1及movie2的目前時間可選擇的影片並把播放時間顯示出來
問一下我想顯示出目前可以觀看影片的時間,不過輸出2個都是null,是哪邊判斷有問題呢??

Viewing all articles
Browse latest Browse all 15645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>