日期--汉字与数字的转换

来源:互联网 发布:云打印机软件 编辑:程序博客网 时间:2024/06/02 04:52

效果

  1. 界面月份数 显示 汉字,参数传入 数字
  2. 查询返回数据时,返回数字,界面显示 汉字

示例:

controller

case 'show'://个人积分来源显示    //获取个人积分页面信息    $year = isset($year) ? intval($year) : date('Y');    $month = isset($month) ? intval($month) : date('n');    $aInfo = $oGrade->getMyGradeInfo($year, $month, $userid);//          var_dump($aInfo);die;    //月份数组    $chine = array("一", "二", "三", "四", "五", "六", "七", "八", "九","十","十一","十二");    include front_tpl('grade.show');    break;

view

<div class="time_select">    <ul>        <li class="left">            <a class="drop" id="year"><?=$year?></a>            <div>                <ul>                <?php for($y = 2015; $y < 2018; $y++){?>                    <li>                        <a <?php if($y == $year){?>class="cur"<?php }?>><?=$y?></a>                    </li>                <?php }?>                </ul>            </div>        </li>        <li class="right">            <a class="drop"  id="month"><?=$chine[$month-1]?></a>            <div>                <ul>                <?php for($m = 1; $m < 13; $m++){?>                    <li>                        <a <?php if($m == $month){?>class="cur"<?php }?>><?=$chine[$m-1]?></a>                    </li>                <?php }?>                </ul>            </div>        </li>    </ul></div><script>    function init(){        var winW=document.documentElement.clientWidth;        var winH=document.documentElement.clientHeight;         var allH=document.documentElement.scrollHeight;        var score_list=document.getElementById("score_list");        var h=winH-(winW*(0.16*640)/640+137);        if(allH<winH){              score_list.style.height=h+"px";        }        $(".drop").click(function(){              $(this).next().toggle();        });        $(".time_select li ul li").click(function(){              $(this).parent().parent().prev().text($(this).find("a").text());            $(this).parent().parent().hide();              //搜索不同年月的个人积分信息            var year = $("#year").text().replace(/年/ig,"");            var month = $("#month").text().replace(/月/ig,"");            month = convertToNumber(month);            window.location.href="?file=grade&action=show&openid=<?=$openid?>&year=" + year + "&month=" + month;        });    }    //汉字转换成数字    function convertToNumber(mon){        var num = ["一", "二", "三", "四", "五", "六", "七", "八", "九","十","十一","十二"];        var len = num.length;        for(var i = 0; i < len; i++){            if(mon == num[i]){                var C_Num = i+1;            }        }        return C_Num;    }</script>

效果图:

这里写图片描述

0 0
原创粉丝点击