CSS/HTML/PHP显示交替数组列表(Google Chrome扩展)



我正在尝试创建一个google chrome扩展,其中几个不同的数组(Name、Age、Country等)被传递到popup.html,并使用html/CSS/PHP显示,类似于:

John Doe nbsp nbsp nbsp 28
美国

Paul Smith nbsp nbsp nbsp;58
日本

Robert Green nbsp nbsp;39
德国

我可以将每个数组传递给popup.html,但只显示最后传递的数组——我还没有找到显示交替数组的每个条目的方法。

在这一点上,我不知道我的方法应该是什么。我应该使用列表,或者改变数组传递到HTML文件的方式,或者有一种简单的方法来显示交替的数组吗?

如有任何帮助,我们将不胜感激!非常感谢。

注:

Name=["John Doe"、"Paul Smith"、"Robert Green"]
年龄=[28,58,39]
国家=[America','Japan','Germany']

编辑-使用示例代码更新

('msg'是从background.js传递到popup.js的用于演示目的的单个数组)

popup.js:

var port = chrome.extension.connect({name: "Sample Communication"});
port.onMessage.addListener(function(msg) {
        document.getElementById('status').textContent = msg;
});

popup.html:

<html>
    <head>
    <script src="popup.js"></script>
        <style type="text/css" media="screen">
            body { 
                min-width       : 400px;
                min-height      : 300px;
                text-align      : right;
                background-color: #D0D0D0; }
           #status { 
                font-size       : 10px;
                color           : #0000CC;
                text-align      : left;
                font-family     : "Times New Roman", Times, serif; }
        </style>
    </head>
    <body>
    <div id="status"></div>
    </body>
</html>

运行此操作只需在逗号分隔的段落中显示数组。从更多的研究来看,使用PHP可能是实现表的最简单方法;但是,我仍然不确定是否可以将数组传递到表中。

每次收到新的数据时,您只需覆盖您的显示器:

port.onMessage.addListener(function(msg) {
  // This wipes the old value:
  document.getElementById('status').textContent = msg;
});

您需要附加数据,或者最好一次传递所有数据,正确格式化数据,然后将其输出到页面。


很难更详细地给出答案,因为:1)你似乎不太清楚自己在做什么,2)这个问题没有确切的说明。

你应该自己多练习,查阅一些教程,否则帮助你对你或其他人都没有真正的帮助。然后,如果你仍然有问题(可能不是特定于扩展的),把它们分成块,然后发到这里。本指南有帮助。

最新更新