Myページ
ホーム
コミュニティの人々
ソフトウェア
技術紹介
適用分野
Tyzohとは
ご意見お問い合わせ

V.S.A. III

カレンダー Ajax 風

こんにちは,五十嵐です.昨日の javascript カレンダーがけっこうウケたみたいなので,調子に乗って,Ajax 風に作ってみました.本当は Ajax でもなんでもなくて,単に DOM を操作しているだけなんですが...

"<<" や ">>" をクリックしてみてください.

日付の数字には,その日に書かれたこの Tyzoh ブログへのリンクを作成してみました.ただし,ブログが書かれていないかどうかは検査していませんので,ブログのない日もあります.このリンクは全然 Ajax 風ではありません(笑)



ソース:
<div id="calendar"></div>

<script type="text/javascript">
<!-- 
function getDayOfTheWeek(year, month, day) {
    if( month < 3 ){
        month += 12;
        year--;
    }

    return (
        year
        + Math.floor( year / 4 )
        - Math.floor( year / 100 )
        + Math.floor( year / 400 )
        + Math.floor( (13 * month + 8) / 5 ) + day
        ) % 7;
}

function make_calendar( year, month, curyear, curmonth ){
    var days = new Array(31, 28, 31, 30, 31, 30, 31, 31,  30, 31, 30, 31);
    if( (((year % 4) == 0)&&((year % 100) != 0)) || ((year % 400) == 0) ){
        days[1]=29;
    }

    var startday = getDayOfTheWeek(year, month, 1);
    var lastday = days[month-1];

    var lastmonth = month - 1;
    var nextmonth = month + 1;
    var lastyear = year;
    var nextyear = year;

    if( lastmonth == 0 ){
        lastmonth = 12;
        lastyear--;
    }
    if ( nextmonth == 13 ) {
         nextmonth = 1;
         nextyear++;
    }

    if( month < 10 ){
        smonth = "0" + month;
    }else{
        smonth = "" + month;
    }

    var calhtml = "";

    calhtml += "<table align=\"center\">";

    calhtml += "<tr><td>";
    calhtml += "<span onmouseover=\"style.cursor='pointer';\" "
            + "onclick=\"rewriteCal("
            + lastyear + "," + lastmonth + ","
            + curyear + "," + curmonth + ")\">"
            + "&lt;&lt;</span></td>";
    calhtml += "<td colspan=\"5\" align=\"center\">"
            + "<a href=\"archive.php?date="
            + year + smonth + "\" target=\"_blank\">"
            + year + "&nbsp;年&nbsp;" + month + "&nbsp;月</td>";
    calhtml += "<td>"
    calhtml += "<span onmouseover=\"style.cursor='pointer';\" "
            + "onclick=\"rewriteCal("
            + nextyear + "," + nextmonth + ","
            + curyear + "," + curmonth + ")\">"
            + "&gt;&gt;</span></td></tr>";

    calhtml += "<tr><td>日</td><td>月</td><td>火</td><td>水</td>";
    calhtml += "<td>木</td><td>金</td><td>土</td></tr>";

    var cols = 0; 
    if( startday != 0 ){
        calhtml += "<tr>";
        for( cols = 0; cols < startday; cols++ ){
            calhtml += "<td>&nbsp;</td>";
        }
    }

    for( day = 1; day <= lastday; day++ ){
        if( cols == 0 ){
            calhtml += "<tr>";
        }
        if( day < 10 ){
            sday = "0" + day;
        }else{
            sday = "" + day;
        }
        calhtml += "<td align=\"right\">"
                + "<a href=\"index.php?date="
                + year + smonth + sday + "\" target=\"_blank\">"
                + day + "</a></td>";                
        cols++;
        if( cols >= 7 ){
            calhtml += "</tr>";
            if( day < lastday ){
                cols = 0;
            }
        }
    }
    for( i = cols; i < 7; i++){
        calhtml += "<td>&nbsp;</td>";
    }

    calhtml += "</tr>";
    calhtml += "<tr><td colspan=\"7\" align=\"right\">";
    calhtml += "<span onmouseover=\"style.cursor='pointer';\" "
            + "onclick=\"rewriteCal("
            + curyear + "," + curmonth + ","
            + curyear + "," + curmonth + ")\">"
            + "今月へ</span></td></tr>";
    calhtml += "</table>";

    return calhtml;
}

function _getElementById( id ) {
    var elem;
    if( document.getElementById ){ // for NS, IE>=5
       elem = document.getElementById( id );
    }else if( document.all ){ // for IE < 5
       elem = document.all( id );
    }else{
       elem = null;
    }
    return elem;
} // end of _getElementById()

function rewriteCal(year,month,curyear,curmonth){
    var cal = make_calendar( year, month, curyear, curmonth );
    _getElementById("calendar").innerHTML = cal;
}

var today = new Date();
var curyear = today.getFullYear();
var curmonth = today.getMonth() + 1;
rewriteCal(2007,6,curyear,curmonth);
// -->
</script>


【追記】
ブログを連続して表示した場合に,昨日のブログ内に記述した javascript と衝突が起こり,正しく動作しない場合がありました.単独で使用する場合にはソースとして表示している javascript で問題ありませんが,このブログでは不都合なため,実際のコードは関数名などを変更して回避しています.

 

カテゴリ:開発日記

いかちょー (2007-06-08 17:02) | コメント(0)| トラックバック(40)

トラックバック(40)

トラックバックURL:

Generic xanax. - Xanax. (2010年12月25日 23:04)

Xanax. Geniric xanax. Generic xanax no prescription. Buying xanax with master... 続きを読む

Xanax no prescription. - Xanax side effects. (2010年12月26日 05:16)

Ativan xanax valuim trial pack. Buy xanax with no prescription. 続きを読む

Xanax. - No rx online xanax. (2010年12月26日 15:35)

Buy xanax. Xanax 2mg no prescription. Xanax. Ativan vs xanax. 続きを読む

Xanax. - Xanax. (2010年12月27日 04:44)

Xanax bars. 続きを読む

Fatal amount of xanax. - Buy xanax online. (2010年12月27日 14:49)

Buy xanax. Discount xanax. 続きを読む

Xanax. - Xanax weight gain. (2010年12月28日 01:12)

Buy generic xanax information. Xanax without prescription. Xanax. Xanax bars. 続きを読む

Psyweb xanax. - Xanax. (2010年12月28日 15:58)

Xanax. Buy xanax online. Xanax withdrawal. 続きを読む

Xanax prescription. - Xanax overdose. (2010年12月29日 03:09)

Xanax while pregnant. Xanax norx needed one day fedex overnight delivery. Xan... 続きを読む

Xanax. - Buy xanax. (2010年12月30日 01:02)

Buy xanax. Xanax. 続きを読む

Buy xanax. - Buy xanax. (2010年12月31日 12:40)

Buy xanax. Xanax. 続きを読む

Buy xanax online. - Generic xanax. (2010年12月31日 23:32)

Buy xanax. Xanax usa. Order xanax online. Cheap xanax. Xanax. 続きを読む

Buy xanax. - Xanax. (2011年1月 1日 13:19)

Buy xanax. Xanax bars. 続きを読む

Offer tramadol. - Offer tramadol. (2011年7月30日 05:43)

Offer tramadol. 続きを読む

Tramadol cod. - Tramadol online cod. (2011年7月31日 05:17)

Tramadol cod. Tramadol cod 89.00. Buy tramadol cod. Tramadol buy cod. Cheap t... 続きを読む

Fioricet indications dosage storage stability butalbital. - What is fioricet butalbital apap. (2011年8月 1日 05:45)

Fioricet butalbital. Butalbital fioricet carisoprodol buy butalbital buy. But... 続きを読む

Online pharmacy abilify. - Online pharmacy abilify. (2011年8月 2日 06:55)

Online pharmacy 2 day shipping abilify. 続きを読む

Lorazepam online. - Lorazepam online. (2011年8月 4日 05:56)

Lorazepam online. 続きを読む

Cheap 60mg prozac. - Buy prozac online cheap without prescription. (2011年8月 6日 07:47)

Cheap prozac. Buy prozac online cheap without prescription. Cheap didrex link... 続きを読む

Buy fioricet. - Buy fioricet. (2011年8月 9日 05:53)

Buy fioricet. 続きを読む

Vicodin. - Vicodin. (2011年8月13日 09:13)

Vicodin. 続きを読む

Order hydrocodone. - Order hydrocodone. (2011年8月15日 05:58)

Order hydrocodone. 続きを読む

Imitrex online. - Imitrex online. (2011年8月19日 05:56)

Imitrex online. 続きを読む

Xanax forte. - Xanax forte. (2011年8月23日 06:26)

Xanax forte. 続きを読む

Buy oxycontin. - Buy oxycontin. (2011年8月26日 06:11)

Buy oxycontin. 続きを読む

Buy amoxicillin. - Buy amoxicillin. (2011年8月28日 06:09)

Buy amoxicillin. 続きを読む

Cheap soma. - Cheap soma. (2011年8月29日 06:11)

Cheap soma. 続きを読む

Order hydrocodone. - Order hydrocodone. (2011年9月10日 06:11)

Order hydrocodone. 続きを読む

Tramadol online. - Tramadol online. (2011年9月14日 06:11)

Tramadol online. 続きを読む

Cheap codeine. - Cheap codeine without prescription. (2011年9月27日 06:05)

Buy cheap codeine link. Cheap codeine. Buy cheap codeine. 続きを読む

Buy strattera online. - Buy strattera online. (2011年10月13日 06:07)

Buy strattera online. 続きを読む

Xanax online. - Xanax online. (2011年10月21日 06:25)

Xanax online. 続きを読む

Ativan lorazepam. - Ativan lorazepam. (2011年10月26日 06:28)

Ativan lorazepam. 続きを読む

Buy strattera. - Buy strattera. (2011年11月 1日 05:56)

Buy strattera. 続きを読む

Order wellbutrin. - Order wellbutrin. (2011年11月 9日 15:17)

Order wellbutrin. General anxiety disorder wellbutrin serzone working. Does w... 続きを読む

Norco online. - Norco online. (2011年11月12日 08:16)

Norco online. 続きを読む

Order ultram. - Order ultram. (2011年11月17日 20:46)

Order ultram. 続きを読む

Order percocet. - Order percocet. (2011年11月18日 19:33)

Order percocet. 続きを読む

Cheap celexa. - Cheap celexa. (2011年11月20日 00:39)

Cheap celexa. 続きを読む

Xanax online. - Xanax online. (2011年11月20日 09:03)

Xanax online. 続きを読む

Order valium. - Order valium. (2011年11月21日 08:43)

Order valium. 続きを読む

コメント

コメントを投稿

名前

電子メール

URL

ログイン情報を記憶

コメント

プロフィール

いかちょー

いかちょーこと五十嵐智です。
情報セキュリティ分野に興味があります。
一応、CISSP ホルダー。

SF者です。どうぞよろしく。

プロフィール詳細 (Google プロフィール)

RSSフィード

コミュニティの人々 | ソフトウェア | 技術紹介 | 適用分野 | Tyzohとは | ご意見お問い合わせ

Copyright (C) 2004-2011 Nihon Unisys, Ltd. All Rights Reserved.
Powered by Movable Type Open Source