javascript - document.evaluate not working in Chrome? - Stack Overflow

I've got the following..var result = doc.evaluate("input[@class="form_field_as as-inp

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 just document – 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
 |  Show 3 more ments

1 Answer 1

Reset to default 5

From http://www.w3/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-evaluate

contextNode of type Node
The context is context node for the evaluation of this XPath expression. If the XPathEvaluator was obtained by casting the Document then this must be owned by the same document and must be a Document, Element, Attribute, Text, CDATASection, Comment, ProcessingInstruction, or XPathNamespace node. If the context node is a Text or a CDATASection, 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

相关推荐

  • javascript - document.evaluate not working in Chrome? - Stack Overflow

    I've got the following..var result = doc.evaluate("input[@class="form_field_as as-inp

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信