【发布时间】:2013-12-28 19:04:10
【问题描述】:
我对 javascript 完全陌生,一个朋友帮我解决了一个问题,我知道它的作用,但我不能真正理解某些部分,我在代码中做了一些 cmets 有一些问题希望你能回答他们。
<html>
<head>
<title>Uppgift 15</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
var resultat = 0;
function addera(){
var t1 = Math.round(object("t1").value);
if (t1 != 0){
resultat += t1;
object("t1").value = "";
}
else{
object("resultat").innerHTML = resultat; // where does "object" come from, what does innerHTML do?
}
}
function object(id){ // i dont get this at all what does this do is there any other way to return?
return document.getElementById(id);
}
</script>
</head>
<body>
<form>
<input id="t1">
<input type="button" onClick=addera() value="resultat">
<p id="resultat"></p>
</form>
</body>
</html>
【问题讨论】:
-
object 只是一个返回元素的函数。
-
它看起来像你的编程新手,不仅仅是 javascript ;)
标签: javascript innerhtml getelementbyid