* Add class with compatibility for SVG since classList is not supported on * SVG elements in IE * *添加与SVG兼容的类,因为不支持类列表 * IE中的SVG元素 *为真实dom 元素添加class类
(el, cls)
| 10844 | *为真实dom 元素添加class类 |
| 10845 | */ |
| 10846 | function addClass(el, cls) { |
| 10847 | /* istanbul ignore if */ |
| 10848 | if (!cls || !(cls = cls.trim())) { |
| 10849 | return |
| 10850 | } |
| 10851 | |
| 10852 | /* istanbul ignore else */ |
| 10853 | if (el.classList) { //如果浏览器支持classList |
| 10854 | if (cls.indexOf(' ') > -1) { |
| 10855 | cls.split(/\s+/).forEach(function (c) { |
| 10856 | return el.classList.add(c); |
| 10857 | }); |
| 10858 | } else { |
| 10859 | el.classList.add(cls); |
| 10860 | } |
| 10861 | } else { //不支持classList 直接用字符串拼接 |
| 10862 | var cur = " " + (el.getAttribute('class') || '') + " "; |
| 10863 | if (cur.indexOf(' ' + cls + ' ') < 0) { |
| 10864 | el.setAttribute('class', (cur + cls).trim()); |
| 10865 | } |
| 10866 | } |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * Remove class with compatibility for SVG since classList is not supported on |
no outgoing calls
no test coverage detected