1 回答
TA贡献1828条经验 获得超4个赞
我想通了!这是因为我有一个内联执行...而不是手动在html中执行onclick=“我的函数()”,我只是通过javascript听它!
这是我更新的代码:
脚本:
function loadSearch() {
var inputResult = document.getElementById("input").value;
var final = 'https://www.google.com/search?q=' + encodeURI(inputResult + '
site:v3rmillion.net');
chrome.tabs.create({url: final});
}
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('button').addEventListener('click', loadSearch, false);
}, false)
网页:
<html>
<head>
<title>Tracillion</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<script type = "text/javascript" src = "popup.js"></script>
</head>
<body>
<h1 class = "header">Enter what you would like to search!</h1>
<div class = "line"></div>
<input class = "input" id = "input">
<button type = "submit" class = "button">Search</button>
</body>
添加回答
举报