IE,Edge和Safari中document.querySelectorAll的兼容性 [英] Compatibility of document.querySelectorAll in IE, Edge and Safari

查看:656
本文介绍了IE,Edge和Safari中document.querySelectorAll的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考答案: https://stackoverflow.com/a/38399344/5132413

请参考我的问题和答案链接

Please refer my question and the answer linked above works only in Firefox, Chrome, and Opera.

我做了一些研究,发现它(不区分大小写的标记)不兼容.我需要IE,Edge和Safari中的同等功能.

I did some research and found that it (case insensitivity flag) isn't compatible. I need an equivalent in IE, Edge and Safari.

var divs = document.querySelectorAll('div[class^="foo" i]');

推荐答案

由于CSS级别4仍在草稿中,因此区分大小写选择器与大多数浏览器不兼容.您可以使用以下过滤方法:

Since css level 4 is still in drafts, case-sensitivity selector is not compatible with most browsers. You may use filter method like this:

var divs = [].slice.call(document.querySelectorAll('div')).filter(function(el){
   return el.className.match(/^foo/i);
});


更新:需要声明您现在可以使用css4选择器.


Update: Need to state that you can now use css4 selector.

document.querySelectorAll('div[class^="foo" i]');

有关浏览器的兼容性,请参见此链接.

See this link for browser compatibility.

这篇关于IE,Edge和Safari中document.querySelectorAll的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆