Chrome扩展程序,span .innerHTML无效

时间:2017-12-23 06:41:39

标签: javascript jquery html5 google-chrome google-chrome-extension

所以我试图在chrome扩展程序中使用 innerHTML 显示计算结果。我的代码在扩展程序之外工作

但是当我运行 chrome扩展程序时,范围似乎没有改变。 我看是否需要任何许可但却找不到任何许可。我真的不明白什么是错的。

的manifest.json

{
  "manifest_version": 2,

  "name": "Raed %",
  "description": "This extension allows the user to calculate percentage",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "activeTab",
    "storage"
  ]
}

function calc(){
	var num1 = document.getElementById('position').value;
	var num2 = document.getElementById('end').value;
	var dis = document.getElementById('result');
	var result = num1 / num2 * num3;
	dis.innerHTML = result + ' % Completed';
}
<!doctype html>
<html>
  <head>
    <title>% CALCULATER</title>
    <style type="text/css">
      body {
        margin: 10px;
        white-space: nowrap;
      }

      h1 {
        font-size: 15px;
      }

      #container {
        align-items: center;
        justify-content: space-between;
      }
    </style>
    <script src="calculate.js"></script>
  </head>

  <body>
    <h1>Percentage Calculater</h1>
    <div id="container">
      <form>
        <input type="text" id="position" placeholder="Position"><br>
        <input type="text" id="end" placeholder="End"><br>
        <input type="button" onClick="calc()" value="Calculate">
        <p>Result:</p>
        <span id = "result">% Completed</span>
      </form>
    </div>
  </body>
</html>

0 个答案:

没有答案