页面操作page_action可以在我的 Github 上找到一种工作方式→ https://github.com/deadcoder0904/insert-remove-ui-chrome-extension/tree/page_action背景.jsvar hasExecutedOnce = falsefunction addUI(tabId) { chrome.tabs.sendMessage(tabId, { from: 'background', subject: 'isUIAdded?', })}chrome.runtime.onInstalled.addListener(function() { chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { chrome.declarativeContent.onPageChanged.addRules([ { conditions: [ new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostEquals: 'www.google.co.in' }, }), ], actions: [new chrome.declarativeContent.ShowPageAction()], }, ]) })})chrome.pageAction.onClicked.addListener(function(tab) { if (!hasExecutedOnce) { chrome.tabs.executeScript( tab.id, { file: 'contentScript.js', }, function() { addUI(tab.id) }, ) hasExecutedOnce = true } addUI(tab.id)})内容脚本.jsvar body = document.getElementsByTagName('body')[0]function insertUI() { var div = document.createElement('div') div.setAttribute('id', 'sample-extension-12345') div.innerHTML = `<h1>Sample Extension</h1>` body.appendChild(div)}function removeUI() { document.getElementById('sample-extension-12345').remove()}function main() { chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if (request.subject === 'isUIAdded?') { const id = document.getElementById('sample-extension-12345') if (id === null) insertUI() else removeUI() } })}main()浏览器操作它还browser_action在 master 分支上有一个解决方案→ https://github.com/deadcoder0904/insert-remove-ui-chrome-extension/背景.jsvar hasExecutedOnce = falsefunction addUI(tabId) { chrome.tabs.sendMessage(tabId, { from: 'background', subject: 'isUIAdded?', })}
1 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
row += "<tr>";之后var row;的结果row === "undefined<tr>"。不要附加到未初始化的变量。使用row = "<tr>";的第一道防线。这也避免了在更新表后附加到相同的变量。
接下来,使用$("#tblscroll tbody").append(row);代替.html。
你也可以缩短函数——不需要某些变量:
function OnSuccess(response) {
//alert("Enter");
const customer = JSON.parse(response.d),
columns = [
"actcode",
"actdesc",
"totamt",
"amt01",
"amt02",
"amt03"
];
$.each(customer, function(i, item) {
console.log("<tr>" + $.map(columns, (prop) => "<td>" + item[prop] + "</td>").join("") + "</tr>");
});
$("#loader").hide();
}
添加回答
举报
0/150
提交
取消