Chrome 扩展内容脚本 DOM 未加载
Chrome Extension content script DOM not loaded
我的内容脚本有问题。
当 oi 运行 它有断点时它工作正常,但没有断点不能正常工作。 $(这个).html(a.farewell);不更新 DOM。
我的清单包含 "run_at":"document_end"
$(function () {
$(document).ready(function () {
console.log("ready!");
var a = "1";
var rows = $("tr.row");
rows.each(function (i) {
var id = $(this).attr("data-bull-id");
chrome.runtime.sendMessage({ getStorage: id }, function (response) {
a = response;
console.log(response.farewell);
$(this).html(a.farewell);
});
// this.innerHTML = a.test;
});
console.log("ready2!");
});
});
我,
我实际上不确定 sendMessage 回调中的 $(this) 是什么。如果您尝试访问单个原始数据,我会将 $(this) 分配给该回调之外的变量。
这条评论帮助我,因为它在 $(this) 中是错误的,"this" 是对消息的引用而不是对元素的引用。
我的内容脚本有问题。
当 oi 运行 它有断点时它工作正常,但没有断点不能正常工作。 $(这个).html(a.farewell);不更新 DOM。
我的清单包含 "run_at":"document_end"
$(function () {
$(document).ready(function () {
console.log("ready!");
var a = "1";
var rows = $("tr.row");
rows.each(function (i) {
var id = $(this).attr("data-bull-id");
chrome.runtime.sendMessage({ getStorage: id }, function (response) {
a = response;
console.log(response.farewell);
$(this).html(a.farewell);
});
// this.innerHTML = a.test;
});
console.log("ready2!");
});
});
我, 我实际上不确定 sendMessage 回调中的 $(this) 是什么。如果您尝试访问单个原始数据,我会将 $(this) 分配给该回调之外的变量。
这条评论帮助我,因为它在 $(this) 中是错误的,"this" 是对消息的引用而不是对元素的引用。