I've got the following..
var result = doc.evaluate("//input[@class=\"form_field_as as-input\"]",
context,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null);
for(var i = 0; i < result.snapshotLength; i++) {
a[i] = result.snapshotItem(i);
}
return a;
The expression I'm evaluating is from an input. The code works fine in FireFox but when I test it on Chrome it doesn't return anything. What am I doing wrong?
The input I'm evaluating is..
<input type="text" id="sharees" class="form_field_as">
I've got the following..
var result = doc.evaluate("//input[@class=\"form_field_as as-input\"]",
context,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null);
for(var i = 0; i < result.snapshotLength; i++) {
a[i] = result.snapshotItem(i);
}
return a;
The expression I'm evaluating is from an input. The code works fine in FireFox but when I test it on Chrome it doesn't return anything. What am I doing wrong?
The input I'm evaluating is..
<input type="text" id="sharees" class="form_field_as">
Share
Improve this question
edited Sep 9, 2015 at 13:08
sideshowbarker♦
88.6k30 gold badges215 silver badges212 bronze badges
asked Feb 10, 2011 at 18:00
SkizitSkizit
45k93 gold badges213 silver badges271 bronze badges
8
- when I'm just checking the javascript console in chrome with your code I get an error that says "doc" is not defined. – Stephen Commented Feb 10, 2011 at 18:38
-
doc
is justdocument
– Skizit Commented Feb 10, 2011 at 18:40 - @Skizit: Apparently not? – jrn.ak Commented Feb 10, 2011 at 18:42
-
sorry, I know that it's supposed to be document not doc. I get a
Uncaught ReferenceError: context is not defined.
Maybe you could post more of the code here so that it will bee more clear as to what these variables are supposed to be. ...ignore my last ment – Stephen Commented Feb 10, 2011 at 18:43 - @Stephen I don't really know what else to add. This is all within an iframe? – Skizit Commented Feb 10, 2011 at 18:47
1 Answer
Reset to default 5From http://www.w3/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-evaluate
contextNode
of typeNode
Thecontext
is context node for the evaluation of this XPath expression. If the XPathEvaluator was obtained by casting theDocument
then this must be owned by the same document and must be aDocument
,Element
,Attribute
,Text
,CDATASection
,Comment
,ProcessingInstruction
, orXPathNamespace
node. If the context node is aText
or aCDATASection
, then the context is interpreted as the whole logical text node as seen by XPath, unless the node is empty in which case it may not serve as the XPath context.
So, your context
must be some instance of these classes. I guess that you probably don't set this variable at all. You could also use null
and the context would bee the node from wich you are evaluating the expression.
Besides that, do note that //input[@class='form_field_as as-input']
is an absolute expression and it will return the same result from any context (outside document context is not allowed when "XPathEvaluator
was obtained by casting the Document
" ).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744764127a4592352.html
评论列表(0条)