[英]onClick with Chrome Extension not working
So I'm pretty new when it comes to java script and creating chrome extensions.所以当涉及到 java 脚本和创建 chrome 扩展时,我很新。 So what I'm trying to do is to take two values which the user has inputted, add them together and display after the user has clicked calculate.
所以我想要做的是取用户输入的两个值,将它们加在一起并在用户点击计算后显示。 However I can't seem to get it to work and I don't know what I'm doing wrong.
但是我似乎无法让它工作,我不知道我做错了什么。 I would greatly appreciate any assistance.
我将不胜感激任何帮助。
Here is my HTML code:这是我的 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<h1>Simple Calculator</h1>
<script src="script.js"></script>
</head>
<body>
First Value<input type="text" id="ValueA"/><br>
Second Value<input type="text" id="ValueB"/><br>
Invested Cost<input type="text" id="result"/><br>
<button id="Calc;">Calculate</button>
</body>
</html>
My java script:我的Java脚本:
document.getElementById("Calc").addEventListener("click", Sum);
function Calc()
{
var A = document.getElementById('ValueA').value;
var B = document.getElementById('ValueB').value;
var C = A+B;
document.getElementById('result').value = C;
}
and finally my manifest:最后是我的清单:
{
"manifest_version": 2,
"name": "Simple Calculator",
"version": "1.0",
"description": "Simple Calculator",
"browser_action":{
"default_popup": "popup.html"
}
}
You need to call Calc()
function in event listener.您需要在事件侦听器中调用
Calc()
函数。 Right now, you are invoking Sum
现在,您正在调用
Sum
Also, as @Julian said in the comment, you need to remove ;
另外,正如@Julian 在评论中所说,您需要删除
;
from button id从按钮 ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.