How do you programmatically clear HTML5 date fields?

后端 未结 10 1263
我在风中等你
我在风中等你 2020-12-11 16:18

I\'m looking for a way to programmatically clear HTML5 date fields with Javascript (specifically jQuery). So far I have tried two methods which I thought obvious:

         


        
相关标签:
10条回答
  • 2020-12-11 16:42

    this line works with my browser (chrome, latest version)

    $('input[type=date]')[0].value = 0;
    
    0 讨论(0)
  • 2020-12-11 16:47

    Can you use the reset function of your form ? You can do this with reset button :

          <button type="reset" value="Reset">Reset</button>
    

    or programmaticaly :

          $("#yourFormId").reset();
    

    or

          $('input[type=date]').reset();
    
    0 讨论(0)
  • 2020-12-11 16:47

    Use the native defaultValue property:

    $('input[type=date]').each( function resetDate(){
      this.value = this.defaultValue;
    } );
    

    This works as long as the form doesn't have an initial value specified, as demonstrated in this fiddle.

    0 讨论(0)
  • 2020-12-11 16:48

    $("input[type=date]").val("") works for me in chrome. It sets the input field to dd/mm/yyyy.

    Maybe it's browser specific. Most browsers have only partial or no support for this input: http://caniuse.com/input-datetime

    0 讨论(0)
提交回复
热议问题