javascript - 为什么我在其他网站上运行时会收到错误 Uncaugt ReferenceError?
问题描述
我的目标是让该工具在网站上运行:one-stop-office-shop.nl 我的工具适用于 codepen.io ( https://codepen.io/teun-van-lith/pen/mdwNYJN )
<script language="javascript" type="text/javascript">
function tcoberekenen(){
const zwart=0.00849;
const kleur=0.05486;
let aantalzwart=document.rekenen.aantalzwart.value;
let aantalkleur=document.rekenen.aantalkleur.value;
var zwarttotaal=document.rekenen.zwarttotaal.value;
var kleurtotaal=document.rekenen.kleurtotaal.value;
var zwarttotaal=aantalzwart*zwart;
var kleurtotaal=aantalkleur*kleur;
var totaal=zwarttotaal+kleurtotaal;
document.rekenen.zwarttotaal.value=zwarttotaal.toFixed(2);
document.rekenen.kleurtotaal.value=kleurtotaal.toFixed(2);
document.rekenen.totaal.value=totaal.toFixed(2);
}
</script>
<div onclick="tcoberekenen()" id="rekentool">
<form name="rekenen" /><input onclick="tcoberekenen()" id="input" name="aantalzwart" />
<div id="inlinetext"><a id="tcotext">x zwart</a></div>
<div id="inlinetext3"><a id="tcotext">€</a></div><input id="output" name="zwarttotaal" /> <br /><input onclick="tcoberekenen()" id="input" name="aantalkleur" />
<div id="inlinetext"><a id="tcotext">x kleur</a></div>
<div id="inlinetext3"><a id="tcotext">€</a></div><input id="output" name="kleurtotaal" />
<div id="inlinetext2"><a id="tcotext">Totale afdrukkosten:</a></div>
<div id="inlinetext4"><a id="tcotext">€</a></div><input id="outputtotaal" name="totaal" />
</form>
</div>
<style>
#input {
border:none;
background-image:none;
background: #666;
height: 30px;
width: 100px;
float:left;
color: white;
padding-left: 10px;
}
#output {
border:none;
background-image:none;
background: #444;
color: white;
size="3";
border:none;
background-image:none;
height: 30px;
width: 100px;
float:left;
}
#outputtotaal {
border:none;
background-image:none;
background: #f58026;
width: 100px;
color: white;
size="3";
border:none;
background-image:none;
height: 30px;
float:left;
}
#rekentool {
color: white;
font-family: verdana;
background: #fff;
width: 340px;
height: 160px;
float:left;
overflow: auto;
}
#tcotext {
color:#fff;
text-decoration: none;
float:left;
font-size: 14px;
padding: 7px;
}
#h2tco {
color: black;
font-size: 20px;
padding-bottom: 10px;
}
#inlinetext {
float:left;
background-color: #f58026;;
width: 70px;
height: 30px;
}
#inlinetext2 {
float:left;
background-color: #444;
width: 170px;
height: 30px;
}
#inlinetext3 {
border:none;
float:left;
background-color: #444;
width: 15px;
height: 30px;
}
#inlinetext4 {
float:left;
background-color: #f58026;
width: 15px;
height: 30px;
}
</style>`
并在标准的html中。
甚至还有这个网站可以使用工具。 https://training.2thenext.nl/i/Rekentool.html
链接到它不起作用的网站: https ://www.one-stop-office-shop.nl/artikel/225638/laserprinter-brother-hl-l9310cdw.html
错误:未捕获的 ReferenceError:tcoberekenen 未在 HTMLInputElement.onclick 中定义(laserprinter-brother-hl-l9310cdw.html:1146)
代码是一样的。我只是不明白。
解决方案
推荐阅读
- java - 仅在线程 1 完成后执行线程 2
- java - 如何在 Android 上使用 libgdx 实现 RewardedVideo 广告?
- c++ - 如何用 char 获得多个输入,用 int 获得多个输出?C++
- e-commerce - 打开电子商务跟踪的问题
- file - 以固定大小的块读取二进制文件并将所有这些块存储到 Vec 中的正确方法是什么?
- python - 如何替换 JSON 列表以打印到 CSV?
- reactjs - ReactiveSearch:是否可以在 SingleDataList 组件上组合标签值?
- c++ - 在 c++ 中使用用户输入初始化数组大小的不同方法有哪些
- postgresql - 如何在 PostgreSQL 11.1 中将现有列更改为身份
- python - 为什么可变和不可变的变量和字符串存在矛盾?