How do you programmatically clear HTML5 date fields?

后端 未结 10 1267
我在风中等你
我在风中等你 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: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.

提交回复
热议问题