gpt4 book ai didi

javascript - 使用 chrome.tabs.executeScript 按 ID 定位 div

转载 作者:行者123 更新时间:2023-12-02 16:54:29 25 4
gpt4 key购买 nike

我正在尝试使用 chrome.tabs.executeScript 来定位页面上的特定 div。

function click(e) {
chrome.tabs.executeScript(null,
{code:"document.body.div#wrap.style.color='" + e.target.id + "'"});
window.close();
}

Consule 告诉我:Uncaught SyntaxError: Unexpected token ILLEGAL

<小时/>

这是一个语法问题,还是不可能?

最佳答案

使用document.querySelector而不是语法上无效的 div#wrap:

chrome.tabs.executeScript(null, {
code: "document.querySelector('div#wrap').style.color='" + e.target.id + "';"
});

关于javascript - 使用 chrome.tabs.executeScript 按 ID 定位 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com