- var $shadow = new Object();
-
- $shadow.domXpath = function(dom) {
- dom = $(dom).get(0);
- var path = "";
- for (; dom && dom.nodeType == 1; dom = dom.parentNode) {
- var index = 1;
- for (var sib = dom.previousSibling; sib; sib = sib.previousSibling) {
- if (sib.nodeType == 1 && sib.tagName == dom.tagName)
- index++;
- }
- var xname = dom.tagName.toLowerCase();
- if (dom.id) {
- xname += "[@id=\"" + dom.id + "\"]";
- } else {
- if (index > 0)
- xname += "[" + index + "]";
- }
- path = "/" + xname + path;
- }
-
- path = path.replace("html[1]/body[1]/","html/body/");
-
- return path;
- };
- $shadow.xpathDom = function(xpath){
-
-
- xpath = xpath.replace(/\/\
-
- xpath = xpath.replace(/\
-
- xpath = xpath.replace(/\[([^@].*?)\]/ig, function(matchStr,xPathIndex){
- var cssPathIndex = parseInt(xPathIndex)-1;
- return ":eq(" + cssPathIndex + ")";
- });
-
- xpath = xpath.replace(/\@/g, "");
-
- xpath = xpath.substr(1);
- alert(xpath);
-
- return $(xpath);
- };
posted @
2016-10-12 15:27
吃饭了吗
阅读(
4500)
评论()
编辑
收藏
举报