$x("//a[contains(@href,'.jpg')]");
Run Code Online (Sandbox Code Playgroud)
从开发人员工具命令提示符按预期工作.但是,当在扩展程序的内容脚本中,我得到一个' $x is not defined'.
为什么这在内容脚本中不可用,或者是否有特殊的方式在内容脚本/ Chrome扩展程序中访问它?
我在Debian上使用Chrome 22.
javascript xpath google-chrome google-chrome-extension content-script
我正在尝试在 Chrome 开发人员控制台中运行一个简单的 JQuery 脚本,但我遇到了问题。
这段代码在 Chrome 开发者控制台上运行时没有问题:
var someValue = $("[name='Jack']");
if(someValue !== null){
console.log("Jack is here!");
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在setTimeout如下函数中运行相同的代码时出现错误:
setTimeout(function(){
var someValue = $("[name='Jack']");
if(someValue !== null){
console.log("Jack is here!");
}
}, 1000);
Run Code Online (Sandbox Code Playgroud)
未捕获的 ReferenceError: $ 未定义
这不仅发生在 setTimeout 函数中,它也发生在普通函数中。
我正在使用最新版本的谷歌浏览器。如何在setTimeout函数中像上面一样使用 JQuery ?