input of date in html5 with a prompt for today

Part 1

I have tried the answer given in "6982692/html5-input-type-date-default-value-to-today" but cannot get it to work for me.

In my .html as the only line in a "div" within a "form" I have:

<input type="date" id="theDate">

There are other divs in that form for other parameters.

And in my .js I have:

$(document).ready(function() {
    var date = new Date();

    var day = date.getDate();
    var mth = date.getMonth() + 1;
    var year = date.getFullYear();

    if (mth < 10) mth = "0" + mth;
    if (day < 10) day = "0" + day;

    var ThisOne = year + "-" + mth + "-" + day;       
    $("#theDate").attr("value", ThisOne);
});

I am expecting the date input box to be populated with today's date. What is displayed is "dd.mm.yyyy". And that is what is displayed without the extra code.

Either way a display box of days in the current month appears on selecting the right hand arrow of the date input box.

I expect today's date will be "correct" more often than not.

Can someone please tell me what am I doing wrong?

Part 2

To assist with testing I would like display the date and other values I actually select.

I have tried "p ..." without success

While I have some texts on HTML4 and am looking online I cannot see a solution I can apply.

I would like to see my values with the HTML halted until I have read them. (It goes on to do something else as soon as all parameter elements in the form are got.)

链接地址: http://www.djcxy.com/p/18666.html

上一篇: 如何设置java.util.Date的时区?

下一篇: 在html5中输入日期并提示今天