A部分:
我知道有很多东西告诉你浏览器是否支持某个HTML5属性,例如http://diveintohtml5.info/detect.html,但他们没有告诉你如何从个人获取类型元素并使用该信息来初始化您的插件.
所以我尝试过:
alert($("input:date"));
//returns "[object Object]"
alert($("input[type='date']"));
//returns "[object Object]"
alert($("input").attr("type"));
//returns "text" ... which is a lie. it should have been "date"
Run Code Online (Sandbox Code Playgroud)
没有人工作.
我最终想出了这个(确实有效):
var inputAttr = $('<div>').append($(this).clone()).remove().html().toLowerCase();
alert(inputAttr);
// returns "<input min="-365" max="365" type="date">"
Run Code Online (Sandbox Code Playgroud)
谢谢:http://jquery-howto.blogspot.com/2009/02/how-to-get-full-html-string-including.html
所以我的第一个问题:1.为什么我不能在不支持html5的浏览器中读取"type"属性?您可以组成任何其他属性和伪造值并阅读它.2.为什么我的解决方案有效?为什么它在DOM中是否重要?
B部分:
以下是我使用探测器的基本示例:
<script type="text/javascript" >
$(function () {
var tM = document.createElement("input");
tM.setAttribute("type", "date");
if (tM.type == "text") {
alert("No date type support on a browser level. Start adding date, week, month, and time …Run Code Online (Sandbox Code Playgroud) 好的,我之前已经问过这个问题,但是哪个日期选择器最适合jQuery mobile(适用于Android?)
日期框 http://dev.jtsage.com/jQM-DateBox2/
Mobiscroll http://mobiscroll.com/
Mobi Pick http://mobipick.sustainablepace.net/demo.html
Datebox和Mobiscroll看起来更成熟,但mobi选择对我来说感觉更快.
另外我听说有些手机(Android)哪些mobiscroll不起作用?