為何我這代碼會執行兩次?
<script type="text/javascript">
//定義函數
function hanshu(a,b){
? ? //函數體,判斷兩個整數比較的三種情況
? ? if(a>b){
? ? ? ? alert(a+"大于"+b);
? ? ? ? return a;
? ? }
? ? else if(a<b)
? ? {
? ? ? ? alert(a+"小于"+b);
? ? ? ? ?return a;
? ? }
? ? else{
? ? ? ? alert("一樣大");
? ? }
};
? ? haha1=hanshu(5,4);
? ? haha2=hanshu(6,3);
? ? haha3=hanshu(3,3);
//調用函數,實現下面兩組數中,返回較大值。
? document.write(" 5 和 4 的較大值是:"+haha1+"<br>");
? document.write(" 6 和 3 的較大值是:"+haha2 );?
</script>
2019-01-03
haha1,haha2,haha3調用執行一次,document.write調用再執行一次,