我的HTML有2个按钮和一个文本输入。它们会更改输入的值(-1和+1)。
它在此处的代码段中工作正常,但在Chrome扩展程序中则无效。
我的HTML文件调用了JavaScript文件,它也在清单中:
<script type="text/javascript" src="melionline.js"></script>
清单:
{
"manifest_version":2,
"name": "Online Console",
"version":"1.0",
"description": "Simulador de consola de Online",
"browser_action":{
"default_icon": "icon24.png",
"default_popup": "PrincipalOnline.html"
},
"permissions":[
"activeTab"
],
"content_scripts": [ {
"js": [ "melionline.js" ]}]
}
document.getElementById("plus").addEventListener("click", changeValue)
var cant=1;
function changeValue() {
if (cant < 5) {
cant += 0.5;
}
else { cant = 5; }
var valor = document.getElementById("counter");
valor.value = cant.toString();
}
document.getElementById("minus").addEventListener("click", changeValue2)
function changeValue2() {
if (cant >1) {
cant -= 1;
}
else { cant = 1; }
var valor = document.getElementById("counter");
valor.value = cant.toString();
}
<button id="minus" style="width:6px; text-align:center;" type="button" class="btn btn-default">-</button>
<input style="text-align:center; width:30px; height:30px;" type="text" id="counter" value="1">
<button style="text-align:center; width:6px;" type="button" id="plus" class="btn btn-default" onclick= "changeValue()" >+</button>