首先,我不是专业的程序员,只是玩一点点.我尝试编写一个小的Chrome扩展程序来管理其他扩展程序.但我已经无法创建一个按钮,我可以点击一个发生的事情.我的主要问题是,在尝试获取elementbyid时,它返回NULL并使用addEventListener失败.也许我只是愚蠢地看到问题.我添加了DOMContentLoaded,因为有人写道,加载内容存在问题.
谢谢您的帮助.
popup.js
var bgp = chrome.extension.getBackgroundPage()
var arr = []; // the array
document.addEventListener('DOMContentLoaded', function () {
var tbinput = document.getElementById("tbinput");
var btadd = document.getElementById("btadd");
btadd.addEventListener('click', addItems());
};
function addItems(){
arr.push(input.value); // add textbox value to array
input.value = ''; // clear textbox value
};
Run Code Online (Sandbox Code Playgroud)
popup.html
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
'browser_action' field in manifest.json contains the 'default_popup' key with
value 'popup.html'.
-->
<html>
<head>
<title>Getting Started Extension's Popup</title> …Run Code Online (Sandbox Code Playgroud)