mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
27 lines
565 B
JavaScript
27 lines
565 B
JavaScript
/**
|
|
* @file 担心会有些浏览器不支持,所以网上抄了一段
|
|
* @author mdn
|
|
*/
|
|
if (!Element.prototype.matches) {
|
|
Element.prototype.matches =
|
|
Element.prototype.msMatchesSelector ||
|
|
Element.prototype.webkitMatchesSelector;
|
|
}
|
|
|
|
if (!Element.prototype.closest) {
|
|
Element.prototype.closest = function (s) {
|
|
var el = this;
|
|
if (!document.documentElement.contains(el)) {
|
|
return null;
|
|
}
|
|
|
|
do {
|
|
if (el.matches(s)) {
|
|
return el;
|
|
}
|
|
el = el.parentElement;
|
|
} while (el !== null);
|
|
return null;
|
|
};
|
|
}
|