Is there any way to change input type=“date” format?

前端 未结 15 1803
清酒与你
清酒与你 2020-11-21 04:17

I\'m working with HTML5 elements on my webpage. By default input type=\"date\" shows date as YYYY-MM-DD.

The question is, is it possible t

15条回答
  •  忘掉有多难
    2020-11-21 05:04

    After having read lots of discussions, I have prepared a simple solution but I don't want to use lots of Jquery and CSS, just some javascript.

    HTML Code:

    
    
    
    

    CSS Code:

    #dt {
      text-indent: -500px;
      height: 25px;
      width: 200px;
    }
    

    Javascript Code :

    function mydate() {
      //alert("");
      document.getElementById("dt").hidden = false;
      document.getElementById("ndt").hidden = true;
    }
    
    function mydate1() {
      d = new Date(document.getElementById("dt").value);
      dt = d.getDate();
      mn = d.getMonth();
      mn++;
      yy = d.getFullYear();
      document.getElementById("ndt").value = dt + "/" + mn + "/" + yy
      document.getElementById("ndt").hidden = false;
      document.getElementById("dt").hidden = true;
    }
    

    Output:

提交回复
热议问题