在HTML、JavaScript或Razor中是否有方法来检测浏览器是否支持<input type="time" />
元素?
提前感谢。
在HTML、JavaScript或Razor中是否有方法来检测浏览器是否支持<input type="time" />
元素?
提前感谢。
当将无效值分配给元素的.type
属性时,这些值将被拒绝。
try {
var input = document.createElement("input");
input.type = "time";
if (input.type === "time") {
console.log("supported");
} else {
console.log("not supported");
}
} catch(e) {
console.log("not supported");
}
如果存在我不知道的浏览器问题,那么使用.innerHTML
应该可以达到相同的效果。var div = document.createElement("div");
div.innerHTML = "<input type='time'>";
if (div.firstChild.type === "time")
console.log("supported");
else
console.log("not supported");
我认为你最好的选择是检查浏览器支持并以编程方式编写使用。
color
输入实际上会被渲染为颜色选择器,但它可以检测出color
是否是有效的type
值(基于卫生处理)。 - Felix Kling