标签:
搜索html中元素常用的是document.querySelector, document.querySelecotrAll,那么验证指定的查询语句跟元素是否匹配呢?可以使用matchsSelector.
function match(htmlEl, query ){ let elPrototype = Element.prototype; let fn = elPrototype.matches || elPrototype.webkitMatchesSelector || elPrototype.mozMatchesSelector || elPrototype.msMatchesSelector; if( fn ){ return fn.call(htmlEl , query ); } throw new Error(‘matchsSelector not be supported‘); }
标签:
原文地址:http://www.cnblogs.com/visonme/p/5380553.html