問題出在什么地方???
<!DOCTYPE? HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數</title>
<script type="text/javascript">
function comp(a,b)
{var a=parseInt(prompt("輸入A值"));
?var b=parseInt(prompt("輸入B值"));
? ? if(a>b){
? ? ? ? return a;
? ? }
? ? else if(a<b){
? ? ? ? return b;
? ? }
? ? else{
? ? ? ? return "兩個值相等"
? ? }
}
</script>
</head>
<body>
? ? <input type="button" onClick="comp()" value="錄入AB值">
</body>
</html>
2022-01-30
沒有打印出來,
var ans=comp()
document.write(ans)
打印出來就可以看見了,結果正確的,代碼沒有問題
2020-11-22
<!DOCTYPE??HTML><html?><head><meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/><title>函數</title><script?type="text/javascript">function?comp(a,b){var?a=parseInt(prompt("輸入A值"));?var?b=parseInt(prompt("輸入B值"));????if(a>b){ //?將結果在控制臺顯示???????console.log(a); ???//?將結果在p標簽內打印出來 ???document.getElementById("num").innerHTML?=?a;????}????else?if(a<b){????????console.log(b); document.getElementById("num").innerHTML?=?b;????}????else{????????console.log("兩者相等"); //?將結果打印出來 document.getElementById("num").innerHTML?=?"兩者相等";????}}</script></head><body>????<input?type="button"?onClick="comp()"?value="錄入AB值"> <p?id="num"></p></body></html>