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

33 篇文章 0 订阅
27 篇文章 0 订阅

效果

  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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值