我刚刚开始自学 JavaScript,并且正在做一些基本的练习。现在我正在尝试制作一个函数,它接受三个值并打印出最大的值。但是,该函数拒绝在按钮单击时触发。我尝试制作一个单独的、非常简单的函数来进行调试,它也拒绝触发。我以几乎完全相同的方式编写了其他练习函数(它们有两个参数而不是三个),它们工作正常。任何见解将不胜感激。
<!DOCTYPE HTML>
<html>
<head>
<script type = "text/javascript">
<!--
//Define a function Max() that takes three numbers as
//arguments and returns the largest of them.
function Boo(){
document.write("boo");
alert("boo");
}
function Max(p1, p2, p3){
document.write(p1+p2+p3);
alert('BOO!')
document.write(document.getElementById('value1').value);
var max = Number(p1);
v2 = Number(p2):
v3 = Number(p3);
if (v2 > max)
max = v2;
if (v3 > max)
max = v3;
document.write(max);
}
-->
</script>
</head>
<body>
<form>
<input type="text" id="value1" name="value1"/><br />
<input type="text" id="value2" name="value2"/><br />
<input type="text" id="value3" name="value3"/><br />
<input type = "button"
onclick="Boo()"
value = "Compare!"/>
<!-- onclick="Max(document.getElementById('value1').value,
document.getElementById('value2').value,
document.getElementById('value3').value)" -->
</form>
</body>
</html>