admin管理员组

文章数量:1399251

I've a problem trying to clear with javascript a form with an input of type="datetime"

because the following code doesen't work when i add input:datetime

$form.find('input:text, input:password, input:file, select, textarea').val('');

Can you help me?

Thank you very much!

I've a problem trying to clear with javascript a form with an input of type="datetime"

because the following code doesen't work when i add input:datetime

$form.find('input:text, input:password, input:file, select, textarea').val('');

Can you help me?

Thank you very much!

Share Improve this question asked Sep 9, 2013 at 16:33 effeffeeffeffe 996 silver badges15 bronze badges 3
  • 3 Why don't you use .reset()? – Dhaval Marthak Commented Sep 9, 2013 at 16:35
  • jQuery does not have :datetime pseudo class... see: api.jquery./category/selectors – gmo Commented Sep 9, 2013 at 16:39
  • Reset() doesnt erase content of input, it just reverts inputs content to its initial state. – pizycki Commented Jul 28, 2014 at 12:16
Add a ment  | 

2 Answers 2

Reset to default 4

You can use input[type=datetime] selector instead.

$form.find('input[type=datetime]').val('');

jsFiddle

You would have to use this selector instead:

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

Since jQuery as of v1.10 does not recognize input:datetime as a valid selector.

See this fiddle

本文标签: jqueryhow to clear input typequotdatetimequot via javascriptStack Overflow