[Front end _easyui] Set default values for Easyui's datebox, not getting the workaround

Source: Internet
Author: User
Tags dateformat

Set the initial value for Eayui Datebox
$ ("#ctime"). Datebox ("SetValue", function () {
var date = new Date ();
var CTime = date.getfullyear () + '-' + (Date.getmonth () +1) + '-' +date.getdate ();
return ctime;
});
Get Datebox value
var time = $ ("#ctime"). Datebox ("GetValue");
Html
Date: <input id= "CTime" class= "Easyui-datebox" editable= "false" style= "width:150px;" >
In this case, the value set for Datebox is displayed on the interface, but it is a blank when acquired.
If you choose a time manually for Datebox, you can get the value you chose
How to get the initial value to the Datebox set????
I have also encountered the same problem, I think it is caused by this, your Datebox initialization is the HTML tag on the style, and the use of the JS. All with JS will be useful.
$ ("#ctime"). Datebox ({
Value:function () {
var date = new Date ();
var CTime = date.getfullyear () + '-' + (Date.getmonth () +1) + '-' +date.getdate ();
return ctime;
}
});

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

The implementation code is as follows:
$ (function () {

$ (' #txtStartTime '). Datebox (' SetValue ', getnowformatdate ());
$ (' #txtStopTime '). Datebox (' SetValue ', getnowformatdate ());
Setdateboxformat ("Txtstarttime", "txtstoptime");

});

function Getnowformatdate () {
return new Date (). Format ("YYYY-MM-DD");//Hh:mm:ss
}

Reference file Dateformat.js
--------------------------------------

Dateformat.js:

//Call Method: Setdateboxformat ("Txtstarttime", "txtstoptime");
Function Setdateboxformat () {
    for (var i = 0; i < arguments.length; i++) {
  &nb sp;     var txtdateboxid = arguments[i];
  
        $ ("#" + Txtdateboxid). Datebox ({
             value:function () {
                 var date = new Date ();
                var ctime = Date.getfullyear () + '-' + (Date.getmonth () + 1) + '-' + date.getdate ();
                return ctime;
           }
       });
   }

}

$ (function () {

Calling method: 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: ("xx" + N). substr (("" + N). length);
}
return format;
};
});


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

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

[Front end _easyui] Set default values for Easyui's datebox, not getting the workaround

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.