附加 html 和动态刷新

Append with html and dynamic refreshing

所以我为一个动态刷新您的钱的网站做了一个扩展,我想要我的扩展中 div 的价值,它似乎根本不刷新或工作。我正在发布相关内容,如果您想知道您要求的任何其他内容,我会提供信息。我正在努力学习 jQuery,所以我还不是最擅长这门语言的。

popup.js

  var cash = $("#v4").html();
  $('.cash').append(cash);

我的分机html页面

<script type="text/javascript">
    $(".cash").append($("#v4").html());
</script>

<div class="cash"></div>

我的错误

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

您必须等待 DOM 加载。现在您正在 $('.cash') 甚至在页面上之前执行代码。试试这个:

$(document).ready( function(){
  $(".cash").append($("#v4").html());
});

尝试

var cash = "<div id='V4'></div>";
$('.cash').append(cash);