harrison
|
分享:
x0
|
[JScript][討論] 煩請高手幫我解答一下~
呼叫函數時並傳入參數值 如 myScore("May","90","100") 不是都要用引號嗎? 但我看到的這個 Avg=myAvg("May","90","100") 用引號反而出不來~ 請高手解答一下~謝謝^^ (一)<html> <head> <title>有傳入參數的函數</title> <script language="JavaScript"> <!-- function myScore(stu_Name,stu_Math,stu_Eng) { //定義myScore函數,並設定3個參數 document.write("<tr><td>學生姓名:"+stu_Name+"</td><td>數學成績:"+stu_Math+"</td><td>英文成績:"+stu_Eng+"</td></tr>"); } //--> </script> </head> <body> <center> <font face="Arial Black" color="#CC3300" size="3"> <img src="images/9.jpg" width="150"> <table width="100%"> <script language="JavaScript"> <!-- myScore("Eileen","90","100"); //呼叫myScore函數並傳入3個參數 myScore("Jennifer","60"); //呼叫myScore函數並傳入2個參數值 myScore("May","70","90","100"); //呼叫myScore函數並傳入4個參數值 //--> </script> </table> </font> </center> </body> </html> (二) <html> <head> <title>傳回值的函數</title> <script language="JavaScript"> <!-- function myAvg(stu_Name,stu_Math,stu_Eng) { //定義myAvg函數,並設定3個參數 stu_Avg=(stu_Math+stu_Eng)/2; return(stu_Avg); //傳回stu_Avg變數的值 } //--> </script> </head> <body> <center> <font face="Arial Black" color="#CC3300" size="3"> <img src="images/9.jpg" width="150"> <table width="100%"> <tr><td>學生姓名:<font face="Arial Black" color="#CC3300" size="3">Eileen</font></td><td>數學成績:<font face="Arial Black" color="#CC3300" size="3">90</font></td><td>英文成績:<font face="Arial Black" color="#CC3300" size="3">100</font></td></tr><tr><td colspan=3> <script language="JavaScript"> <!-- //呼叫myAvg函數並傳入3個參數,stu_Avg變數接收傳回的值 Avg=myAvg("Eileen",90,100); document.write("平均成績:"+Avg); //--> </script> </td></tr> </table> </font> </center> </body> </html>
|