为了账号安全,请及时绑定邮箱和手机立即绑定

在 jQuery 表绑定中获取更多数据时,如何将旧数据保留在表体中?

在 jQuery 表绑定中获取更多数据时,如何将旧数据保留在表体中?

holdtom 2021-08-20 14:29:21
页面操作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条经验 获得超6个赞

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();

}


查看完整回答
反对 回复 2021-08-20
  • 1 回答
  • 0 关注
  • 117 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信