检测< input type =" file" />得到支持 [英] Detect if <input type="file" /> is supported
问题描述
我正在构建我的网站的移动版本,该版本具有文件上传工具,可通过上传按钮访问
I'm building a mobile version of my site which has a file upload facility, accessed via an 'Upload Button'
我想隐藏按钮iPhone用户,因为控件只显得灰白 - 这可能吗?
I would like to hide the button from iPhone users, as the control just appears greyed out - is this possible?
我真的不想检测iPhone;我觉得检测这个功能要好得多 - 如果Apple启用它(或手机是Jailbroken,或其他东西......),它会自动开始工作。
I don't really want to detect the iPhone; I feel it would be much better to detect the feature - making it start to work automatically should Apple enable this (or the phone is Jailbroken, or something...)
推荐答案
检查是否实现输入[type = file]
的函数:
function isInputTypeFileImplemented() {
var elem = document.createElement("input");
elem.type = "file";
if (elem.disabled) return false;
try {
elem.value = "Test"; // Throws error if type=file is implemented
return elem.value != "Test";
} catch(e) {
return elem.type == "file";
}
}
小提琴: http://jsfiddle.net/8EqEE/9
Fiddle: http://jsfiddle.net/8EqEE/9
这篇关于检测< input type =" file" />得到支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!