包括javascript到谷歌网站 [英] Including javascript to google sites
本文介绍了包括javascript到谷歌网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个简单的JavaScript添加到Google协作平台,但按下按钮时我什么都没得到。我把代码放在HTML Box中。在本地测试时,代码可以正常工作。这是我的代码:
I'm trying to include a simple javascript to Google Sites but I get nothing when pressing the button. I put the code inside an HTML Box. The code works perfectly when tested locally. Here is my code:
<script>
function calcul(){
x = parseFloat(document.getElementById("value1").value);
y = parseFloat(document.getElementById("value2").value);
document.getElementById("answer").innerHTML=x+y;
}
</script>
<form action="" id="nothing">
<input type="text" id="value1">
<input type="text" id="value2">
<input type="button" value="Calculate" id="but" onclick="calcul()" />
<p id="answer"></p>
有什么我忘了让它起作用吗?
Is there something I forgot to make it work?
推荐答案
Google协作平台会更改整个脚本。你必须更仔细地编写JavaScript。
Google Sites changes your entire script. You have to be a bit more careful writing JavaScript.
在每个变量前添加 var
将解决你的问题:
Adding var
in front of every variable will fix your problem:
<script>
function calcul(){
var x = parseFloat(document.getElementById("value1").value);
var y = parseFloat(document.getElementById("value2").value);
document.getElementById("answer").innerHTML=x+y;
}
</script>
<form action="" id="nothing">
<input type="text" id="value1">
<input type="text" id="value2">
<input type="button" value="Calculate" id="but" onclick="calcul()" />
</form>
<p id="answer"></p>
这将有效; - )
这篇关于包括javascript到谷歌网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文