みんな私はこれに夢中になっていて、javascriptを使用する制約がたくさんあることを知っていますが、私が構築しているサイトにはhtmlファイルしかありません。phpも使用できますが、参照できるが含まれていない別のファイルである必要があります。最終的な拡張子は .html にする必要があります
そうは言っても、日付を含む画像名を持つ画像のディレクトリを取得するスクリプトの写真を作成しています。たとえば、今日の今日の画像は20120822.jpgで、年末までの膨大な画像ディレクトリがあります。明日の画像は20120823.jpgで、昨日は20120821.jpg です
その部分は簡単でした..しかし、今は以前に表示されたすべての画像から構成されたギャラリーを作成したい..現在の日付のファイル名に至るすべての画像. したがって、ディレクトリを読み取るか、現在のイメージの日付ファイル名につながる最後の 20 個のイメージを生成する必要があります。前の 20 枚の画像か何かで解決します。
ここに私がその日の写真に使用しているコードがあります..どうすればいいですか?
<script>
//returns the current date in YYYYMMDDf_01.jpg format
function getCurrentDateString(){
//make a new date object set at the current date
var currentDate = new Date();
//get the four position year and
//make it a string
var currentYear = currentDate.getFullYear() + "";
//get the zero-indexed month and add 1
//for the real month and make it a strintg
var currentMonth = (currentDate.getMonth() + 1) + "";
//add a zero at the beginning if only one
//digit month
if (currentMonth.length == 1) {
currentMonth = "0" + currentMonth;
}
//get the current day of the month and
//make it a string
var currentDayOfMonth = currentDate.getDate() + "";
//add a zero if necessary
if (currentDayOfMonth.length == 1) {
currentDayOfMonth = "0" + currentDayOfMonth;
}
return(currentYear + currentMonth + currentDayOfMonth);
}
//preload image based upon currentDate
var currentDateString = getCurrentDateString();
var dailyImageObject = new Image();
var dailyImageObjectURL = new Image();
dailyImageObject.src = "http://perillotours.com/galleries/photo-of-the-day/images/" + currentDateString + ".jpg";
dailyImageObjectURL.href = "http://perillotours.com/galleries/photo-of-the-day/images/" + currentDateString + ".jpg";
//called when the page loads to
//set the actual HTML IMG element to have the same
//SRC as our cached Image object
function showDailyImage(){
document.getElementById("dailyIMGElement").src = dailyImageObject.src;
}
function showDailyImageURL(){
document.getElementById("dailyIMGElementURL").href = dailyImageObjectURL.href;
}
</script>
これは、その日の写真を表示するために HTML ページに配置するコードです。
<a rel="prettyphoto" id="dailyIMGElementURL">
<img width="523" style="background-color: #000000;" id="dailyIMGElement" height="335" border="0" /></a>
したがって、基本的には、最後の 20 枚の画像で上記のコードを 20 回ループしたいと考えています。私は本当にそれを行う方法を考えることはできません..
ヘルプやアイデアをお寄せいただきありがとうございます。
イアン