easyui的datebox只顯示年月


要求點擊easyui的datebox時只顯示年月,隱藏日,之前百度了好多,發現有的好麻煩,有的使用沒效果,也許自己沒理解,改不了.最后老員工幫我搞定了,添加一個fomatter和一個parser函數就行.

當然我學習到的一點就是調試,之前只會用類似alert和console.info進行調試,然而這兩種方法對easyui中的這種方法不奏效,比我我想知道parser中的function中的參數date值到底是什么,用這兩種方法是沒用的,用console.log(date);就可以看到date的值,真是太好了,否則錯了都不知道哪錯了,不知道date值是多少都無法進行對應的邏輯操作.

    $(function(){
            var currTime=new Date();
            var strDate=currTime.getFullYear()+"-"+(currTime.getMonth()+1)+"-01";
            $('#dateid').datebox({formatter:function(date){
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? '0' + m : m;
                return y.toString() + '-' + m.toString();
            },parser:function(date){
                console.log(date);
                if (date) {
                    return new Date(String(date).substring(0, 4) + '-'
                            + String(date).substring(5,7));
                } else {
                    return new Date();
                }
            }});
            $('#dateid').datebox('setValue',strDate);//默認加載當前月份
            
        });
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM