jQuery 移动设备的时间选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5522880/
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
Time Picker for mobile devices
提问by Mustehsan Ikram
I am working in HTML5, CSS3 and using jQuery for my project. I need to have a time picker only - no date picker - for mobile devices like iPad, Galaxy etc. It should work with both touchscreen and non-touchscreen devices. I found one with a slider but it failed on mobile devices.
我正在使用 HTML5、CSS3 并在我的项目中使用 jQuery。我只需要一个时间选择器 - 没有日期选择器 - 用于 iPad、Galaxy 等移动设备。它应该适用于触摸屏和非触摸屏设备。我找到了一个带有滑块的,但它在移动设备上失败了。
回答by fretje
I've found another one which looks quite good. It also has different styles for different platforms: mobiscroll
我找到了另一个看起来很不错的。它也有针对不同平台的不同风格:mobiscroll
回答by Jhollman Cutcsa
Im glad to tell you that there is no need for a third party plugin in order to get the time-picker functionality.
我很高兴地告诉您,无需第三方插件即可获得时间选择器功能。
HTML5 has already a native time picker wich is very easy to implement:
HTML5 已经有一个非常容易实现的本地时间选择器:
<label for="timePicker1">Set Time:</label>
<input type="time" name="timePicker1" id="timePicker1" value="10:00">
Read and write the value is equally easy with jQuery:
使用 jQuery 读取和写入值同样容易:
var time = $('#timePicker1').val(); //<- Get value
$('#timePicker1').val("09:30"); //<- Set value
The value for either set/get is an string with format 'hh:mm'.
set/get 的值是格式为“hh:mm”的字符串。
It works as intended on JQuery Mobile 1.4.2.
它在 JQuery Mobile 1.4.2 上按预期工作。
There is also another usefull HTML5 controls here: http://www.w3schools.com/html/html5_form_input_types.asp
这里还有另一个有用的 HTML5 控件:http: //www.w3schools.com/html/html5_form_input_types.asp
Regards.
问候。
回答by Francois Gelinas
I wrote this jQuery Time Picker based on the existing Datepicker but for time only. Never tried it on a mobile device but I think it will work well.
我根据现有的 Datepicker 编写了这个 jQuery 时间选择器,但仅用于时间。从未在移动设备上尝试过,但我认为它会很好用。
You can try it at : http://fgelinas.com/code/timepicker
您可以在以下网址尝试:http: //fgelinas.com/code/timepicker
回答by headwinds
Interesting problem -- I tried out the first Jquery datepicker (includes timepickers) example:
有趣的问题——我尝试了第一个 Jquery 日期选择器(包括时间选择器)示例:
http://plugins.jquery.com/project/cantipi
http://plugins.jquery.com/project/cantipi
It works once on my iPhone but then fails to respond to further touch events.
它在我的 iPhone 上运行一次,但无法响应进一步的触摸事件。
Then I tried the second one: Calendrical
然后我尝试了第二个:日历
http://tobiascohen.com/demos/calendrical/
http://tobiascohen.com/demos/calendrical/
I could set the time and reset it on the iPhone. Did you try it?
我可以设置时间并在 iPhone 上重置它。你试了吗?
You might also look at Sencha for the touch events and consider its timer.
您还可以查看 Sencha 的触摸事件并考虑它的计时器。
回答by Clay
It looks like jQuery mobile updated their date and time picker code recently. Have a look at the demos here (that may only work properly on a mobile device): http://jquerymobile.com/test/docs/forms/textinputs/
看起来 jQuery mobile 最近更新了他们的日期和时间选择器代码。看看这里的演示(可能只能在移动设备上正常工作):http: //jquerymobile.com/test/docs/forms/textinputs/
回答by Greg
I was looking for a native timepicker rather than a bespoke one. Found this which works really well on Android 4.0+. I haven't tested yet on iOS.
我正在寻找一个本地时间选择器,而不是一个定制的。发现这个在 Android 4.0+ 上运行得非常好。我还没有在 iOS 上测试过。