JQuery输入[type = date]选择器 [英] JQuery input[type=date] selector

查看:618
本文介绍了JQuery输入[type = date]选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我输入的类型设置为date(html5):

I have an input with the type set as "date" (html5):

<input id="Employee_hireDate" class="pickDate" type="date" name="Employee[hireDate]" value="Hire Date" />

当我查看原始来源时,类型设置为日期。但是,在Chrome开发人员工具中,它不会显示。当我运行:

When I view the raw source, the type is set as date. However, in Chrome Developer Tools it is not displayed. And when I run:

alert($('#Employee_hireDate').attr('type'));

它将输入类型显示为未定义。我正在使用Google Chrome v15。

It shows the input type as undefined. I'm using Google Chrome v15.

有没有人知道为什么JQuery找不到选择器?

Does anyone have an idea of why JQuery can't find the selector?

Logan

推荐答案

这样做真的不应该这样做。 HTML5日期有一些非常具体的UI和一个非常具体的API。例如,以下代码 http://jsfiddle.net/trixta/EAZPN/ 在Opera中不起作用如果浏览器完全实现了type =date,则Chrome或其他任何浏览器将无法正常工作。

You really should not do this, this way. HTML5 date has some very specific UI and a very specific API. For example the following code http://jsfiddle.net/trixta/EAZPN/ does not work in Opera and it won't be working in Chrome or any other browser, if the browser has implemented type="date" fully.

如果您希望使其不可行,您必须删除日期并用类型文本替换它。此外,您必须确保,您始终以以下格式YYYY-MM-DD使用/生成日期值。

If you want to make this somehow workable, you have to remove the date and replace it with type text. Additionally you have to make sure, that you always use/generate date-value in the following format YYYY-MM-DD.

还有很多其他要做的事情这真的很好我使用 webshims lib 举个例子,其中你可以在这里找到: http://jsfiddle.net/trixta/VNuct/

There are a lot of other things to make this really good. I have made a small example using webshims lib, which you can find here: http://jsfiddle.net/trixta/VNuct/.

Webshims lib将隐藏您的原始类型=日期输入,并创建一个无名的新的,以模拟日期戳的视觉实现。它还将输入的值从一个输入传输到另一个输入,并将该值转换为正确的格式。它还为您提供了完整的HTML5日期API:

Webshims lib will hide your original type="date" input and creates a nameless new one, to mimic the visual implementation of a datepicker. It also transfers the input's value from one input to another and transforms this value into the right format. It also gives you the full HTML5 date API:

例如:

$('#Employee_hireDate').prop('valueAsNumber', 1315267200000);
$('#Employee_hireDate').prop('valueADate');

这篇关于JQuery输入[type = date]选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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