我寫此功能讓XPath位置:jQuery函數實現
JQuery的(該功能獲取的XPath):
function getXPath(node, path) {
path = path || [];
if(node.parentNode) {
path = getXPath(node.parentNode, path);
}
if(node.previousSibling) {
var count = 1;
var sibling = node.previousSibling
do {
if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {count++;}
sibling = sibling.previousSibling;
} while(sibling);
if(count == 1) {count = null;}
} else if(node.nextSibling) {
var sibling = node.nextSibling;
do {
if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {
var count = 1;
sibling = null;
} else {
var count = null;
sibling = sibling.previousSibling;
}
} while(sibling);
}
if(node.nodeType == 1) {
path.push(node.nodeName.toLowerCase() + (node.id ? "[@id='"+node.id+"']" : count > 0 ? "["+count+"]" : ''));
}
return path;
};
,我有一個iframe:
<iframe id="frameID" width="100%" src="http://www.example.com"></iframe>
,但現在我有一個問題,如何將我的jquery函數和當我點擊iframe中的某處獲取xpath結果的位置?
對於你需要什麼jQuery?你是否自己寫了xpath函數? – Bergi
我需要獲得結果,當我點擊... – Andrew