-6ren"> -有没有办法在 HTML、javascript 或 Razor 中检测浏览器是否支持 元素? 提前致谢。 最佳答案 当分配给 input 元素的 .type 属性时,无效值将被拒绝。 try { -6ren">
gpt4 book ai didi

javascript - 如何检查浏览器是否支持<input type ="time"/>

转载 作者:技术小花猫 更新时间:2023-10-29 12:38:18 26 4
gpt4 key购买 nike

有没有办法在 HTML、javascript 或 Razor 中检测浏览器是否支持 <input type="time" />元素?

提前致谢。

最佳答案

当分配给 input 元素的 .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");

关于javascript - 如何检查浏览器是否支持&lt;input type ="time"/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21840574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com