javascript - 在 Firefox/IE 上隐藏元素,仅在 chrome 上显示

标签 javascript css webkit input-type-file

我正在使用 <input type="file" webkitdirectory>在 Chrome 上选择文件夹。虽然我知道此功能仅适用于 Chrome,但我想在不支持它的浏览器(如 Firefox 和 IE)上隐藏此按钮。

我找到了一篇建议执行类似以下代码的帖子,但它在 chrome 和 FF 上都返回 false。

$scope.isDirSupp = function() {
    var tmpInput = $('#bulkyFolder');
    if ('webkitdirectory' in tmpInput 
        || 'mozdirectory' in tmpInput 
        || 'odirectory' in tmpInput 
        || 'msdirectory' in tmpInput 
        || 'directory' in tmpInput) return true;

    return false;
}

html: <input type="file" webkitdirectory id="bulkyFolder" ng-show="isDirSupp">

在 Chrome 上显示此按钮并在 Firefox 和 IE 上隐藏它的最佳方式是什么?

最佳答案

您可以使用 CSS 仅在 Chrome 上显示输入元素。

#bulkyFolder {
  display: none;
}
#bulkyFolder:not(*:root) { /* Supports only WebKit browsers */
  display: block;
}
<input type="file" webkitdirectory id="bulkyFolder" ng-show="isDirSupp">

关于javascript - 在 Firefox/IE 上隐藏元素,仅在 chrome 上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32141052/

相关文章:

Android/iPhone 链接样式

css - -safari 中的 webkit-animation-fill-mode

javascript - 您调用原型(prototype)函数的元素是什么?

Javascript:更改 <h2> 标题颜色 onmouseover()

javascript - HTML/JavaScript : How to run a loop while running other code?

HTML CSS : Hover Property not Working on Google Icon

c# - WPF中如何使用WebKit浏览器控件

windows - Windows下使用PyQt的Webkit无法通过xhr获取远程资源

javascript - 将元素悬停在图表上

javascript - 为什么js认为我的数组在某些环境下不是数组?