【问题标题】:(document.evaluate) -> src of image contains multiple conditions, how?(document.evaluate) -> 图像的 src 包含多个条件,如何?
【发布时间】:2011-04-13 10:34:41
【问题描述】:

请不要用仇恨棒打我。我是菜鸟。 躲在角落里

我是 Greasemonkey 及其语法的新手,非常感谢您的帮助!

我正在尝试根据 src url 中包含的单词突出显示几个图像,但如果 src 不是一个完整的匹配项,我无法找出多个条件的正确语法。

var snapImages =document.evaluate("//img[contains(@src, 'car']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);


for (var i = snapImages.snapshotLength - 1; i >= 0; i--) {
        var elmImage = snapImages.snapshotItem(i);

    elmImage.style.MozOutline = "5px solid red";
    }

此示例有效,但我需要更多条件。像 (@src, 'bike'), (@src, 'bus') 等等。我再次为这个新手问题道歉。什么是正确的语法?

非常感谢!

-洛奇

【问题讨论】:

    标签: javascript xpath greasemonkey document.evaluate


    【解决方案1】:

    您可以在 XPath 谓词中使用 andor,例如:

    //img[contains(@src, 'car') or contains(@src, 'bike')]
    

    优先级在Booleans section of the spec 中定义。

    【讨论】:

    • 哦,非常感谢!我试过了,但没有或没有括号...谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 2020-07-30
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多