MCPcopy
hub / github.com/gongjunhao/seckill / getDomPath

Function getDomPath

src/js/newTask.js:154–179  ·  view source on GitHub ↗

* 根据点击元素 获取Jquery path * @param el * @returns {Array.<*>}

(el)

Source from the content-addressed store, hash-verified

152 * @returns {Array.<*>}
153 */
154function getDomPath(el) {
155 var stack = [];
156 while ( el.parentNode != null ) {
157 var sibCount = 0;
158 var sibIndex = 0;
159 for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {
160 var sib = el.parentNode.childNodes[i];
161 if ( sib.nodeName == el.nodeName ) {
162 if ( sib === el ) {
163 sibIndex = sibCount;
164 }
165 sibCount++;
166 }
167 }
168 if ( el.hasAttribute('id') && el.id != '' ) {
169 stack.unshift(el.nodeName.toLowerCase() + '#' + el.id);
170 } else if ( sibCount > 1 ) {
171 stack.unshift(el.nodeName.toLowerCase() + ':eq(' + sibIndex + ')');
172 } else {
173 stack.unshift(el.nodeName.toLowerCase());
174 }
175 el = el.parentNode;
176 }
177
178 return stack.slice(1);
179}
180
181/**
182 * 根据点击元素 获取 xPath

Callers 1

newTask.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected