javascript HTML5 jQuery 选择所有日期字段“输入:日期”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16718074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML5 jQuery select all date fields 'input:date'
提问by Roar
Is there a way to select all date inputs?
I have:
有没有办法选择所有日期输入?
我有:
<input type="date" name="bday">
all i need it's just to select all inputs.
there are many selectors, but nothing like:
我所需要的只是选择所有输入。
有很多选择器,但没有像:
$('input:date')
this approach
这种方法
$("input[type='date']")
looks no good
看起来不好
What's the best practice?
最佳做法是什么?
回答by victor
If you want something cross browser, you should stick with:
如果你想要跨浏览器的东西,你应该坚持:
$('input[type="date"]')
I don't think you can select all inputs of type date in a different way. If however you want to select all text fields you can go with
我认为您不能以不同的方式选择所有日期类型的输入。但是,如果您想选择所有文本字段,则可以使用
$(':text')
or if you want all radios you can go with
或者如果你想要所有的收音机,你可以去
$(':radio')
回答by Karl-André Gagnon
The cleanest way is to add a class "date" to all your input and select them with $('.yourClass')
.
最简洁的方法是在所有输入中添加一个“日期”类,并使用$('.yourClass')
.
If you can't add class, i don't see why $("input[type='date']")
"look no good".
如果你不能添加类,我不明白为什么$("input[type='date']")
“看起来不好”。
Maybe you want something like $('input').filter('[type=date]')
?
也许你想要这样的东西$('input').filter('[type=date]')
?