zoukankan      html  css  js  c++  java
  • [前端_EasyUI]给easyui的datebox设置默认值,获取不到 的解决方法

    //给eayui datebox设置初始值
    $("#ctime").datebox("setValue", function(){
    var date = new Date();
    var ctime = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
    return ctime;
    });
    //获取datebox值
    var time = $("#ctime").datebox("getValue");
    //HTML
    日期:<input id="ctime" class="easyui-datebox" editable="false" style=" 150px;">
    这样写,给datebox设置的值,在界面上展示了,但是获取的时候是个空白,
    如果再手动去给datebox选一个时间,就能获取到手选的值,
    怎样获取到给datebox设置的初始值呢????
     
    我也遇到过同样的问题,我觉得是因为这个引起的,你的datebox初始化的时候是在html标签上加的样式,而用的时候是用的js。都用js就会好用的。
    $("#ctime").datebox({
    value:function(){
    var date = new Date();
    var ctime = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
    return ctime;
    }
    });
     

    -------------------------------------------------------------------------------------

    实现代码如下:
    $(function () {

    $('#txtStartTime').datebox('setValue', getNowFormatDate()); 
    $('#txtStopTime').datebox('setValue',getNowFormatDate()); 
    SetDateBoxFormat("txtStartTime","txtStopTime");

    });

    function getNowFormatDate() {
           return new Date().format("yyyy-MM-dd");// hh:mm:ss
       }

    引用文件dateFormat.js
    --------------------------------------

    dateFormat.js :

    //调用方法:SetDateBoxFormat("txtStartTime","txtStopTime");
    function SetDateBoxFormat() {
        for (var i = 0; i < arguments.length; i++) {
            var txtDateBoxId = arguments[i];
      
            $("#" + txtDateBoxId).datebox({
                value: function () {
                    var date = new Date();
                    var ctime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                    return ctime;
                }
            });
        }

    }

    $(function () {

        //调用方法:new Date().format("yyyy-MM-dd hh:mm:ss")
        Date.prototype.format = function(format) {
            var args = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
                "S": this.getMilliseconds()
            };
            if (/(y+)/.test(format))
                format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var i in args) {
                var n = args[i];
                if (new RegExp("(" + i + ")").test(format))
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
            }
            return format;
        };
    });


    --------------------------------------

    -------------------------------------------------------------------------------------

  • 相关阅读:
    Effective JavaScript: 编写高质量JavaScript代码的68个有效方法(目录)
    第 13 条:使用立即调用的函数表达式创建局部作用域
    第11条:javascript闭包(Effective JavaScript读书笔记)
    .net各类视频教程
    IIS7视频教程
    快速排序
    冒泡排序
    python骚气的写法:b = lambda i, x: (tf.compat.v1.Print(i + 1, [i]), tf.compat.v1.Print(x + 1, [i], "x:"))
    服务器要放到水下
    keras包含各种内置层
  • 原文地址:https://www.cnblogs.com/jx270/p/4576758.html
Copyright © 2011-2022 走看看