如何以编程方式清除HTML5日期字段? [英] How do you programmatically clear HTML5 date fields?

查看:137
本文介绍了如何以编程方式清除HTML5日期字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用Javascript(特别是jQuery)以编程方式清除HTML5日期字段的方法。到目前为止,我已经尝试了两种方法,我觉得很明显:

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:

$('input[type=date]').val('');

$('input[type=date]').val('0000-00-00');

但是,他们至少没有在最新版本的Chrome for PC上工作,还没有尝试过与其他浏览器或平台。是否有API调用或可以以跨浏览器方式清除日期字段的东西?我搜索过的解决方案,如需要用户清除日期字段,而我需要这样做是以编程方式完成的。

But neither of them work on the latest version of Chrome for PCs at least, haven't tried them with other browsers or platforms yet. Is there an API call or something that can clear date fields in a cross-browser way? Solutions I have searched for like this require the user to clear the date field whereas I need this to be done programmatically.

推荐答案

$(input [ date])。val()在chrome中为我工作。它将输入字段设置为dd / mm / yyyy。

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

也许它的浏览器具体。大多数浏览器只支持部分或不支持此输入: http://caniuse.com/input-datetime

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

这篇关于如何以编程方式清除HTML5日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆