代碼錯在那里?
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)</title>
<script type="text/javascript">
function compare(a,b){
//定義函數(shù)
if(a>b){
? ? return a;
}
?else if(a==b){
? ? ?return '一樣大';
?}
else{
return a;
}
?}
?document.write(" 5 和 4 的較大值是:"+"compare"+"<br>");
?document.write(" 6 和 3 的較大值是:"+"compare" );?
</script>
</head>
<body>
</body>
</html>
以上是我的代碼,為什么瀏覽器是空白的?
2015-09-04
?document.write(" 5 和 4 的較大值是:"+"compare"+"<br>");
?document.write(" 6 和 3 的較大值是:"+"compare" );
把這兩行代碼改成
?document.write(" 5 和 4 的較大值是:"+compare(5,4)+"<br>");
?document.write(" 6 和 3 的較大值是:"+compare(6,3) );
就行了。
2015-09-04
還有
function compare(a,b){
if(a>b){
? ? return a;
}
?else if(a==b){
? ? ?return "一樣大"; ? ?//你這里的分號是中文輸入,導致你的compare函數(shù)無法運行了,把它改成英文輸入就行了
?}
else{
return b;
}
?}