javascript - Why does .prop("type") return "text" on a datetime input? -
given simple code:
<html> <body> <input type="datetime" id="theinput"/> <script type="text/javascript" src="./jquery-3.2.1.min.js"></script> <script type="text/javascript"> $(document).ready(function (){ alert($("#theinput").prop("type")); }); </script> </body> </html>
you'd think messagebox "datetime", wouldn't it? apparently doesn't, says "text". how , why jquery deciding ignore wrote type? shouldn't able write arbitrary type "type" property , see messaged me? there list of jquery thinks types should be?
(and aside, don't attempt put jsfiddle or codepen. both of reason refuse run javascript. don't know if i'm not allowed use "prop" or if i'm not allowed search id, or what.)
inputs of type datetime aren't supported anymore.
the browser replaces them inputs of type text. that's why type property of input "text"
.
a solution use inputs of type datetime-local
.
console.log("type : " + document.getelementbyid("a").type); console.log("type b : " + document.getelementbyid("b").type);
<input id=a type=datetime> <input id=b type=datetime-local>
of course read attribute value (using attr
jquery) hide real input's type.
Comments
Post a Comment