以下是我编写的JS 档: try3.jswindow.onload = today();
window.onload = askNameGreet();function askNameGreet(){var name;
var hour = new Date();
var hours = hour.getHours();name = prompt ("Nice to meet you. \May I know your name?", "Peter");
if ( hours <= 11) document.write("<font color = "green"><b>Good morning!"</b></font>);
else 
if ( hours <= 18) document.write("<font color = "green"><b>Good afternoon!"</b></font>);
else 
if ( hours <= 23) document.write("<font color = "green"><b>Good evening!"</b></font>);
document.write(" " + <font color = "green"><b>name</b></font>);}function today(){var season;
var day = new Date();
var month = day.getMonth() + 1;
var date = day.getDate();
var year = day.getFullYear();
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var toDay = weekday[toDay.getDay()];if (year < 2000) year = year + 1900;
if (month >= 3 && month <= 4) season = "Spring ";
if (month >= 5 && month <= 8) season = "Summer ";
if (month >= 9 && month <= 10) season = "Autume ";
if (month >= 11 || month <= 2) season = "Winter ";
document.write(<font color = "pink"><b>"Today is " + year + " \/ "  + month + " \/ " + date + ", " + weekday[day.getDay()] + ", " + "Season is: " + season</b></font>);}下面是网页里的代码:<html>
<head>
<title>test JavaScript file 2</title>
<script type = "text/javascript" scr = "scripts/try3.js">
</script>
<style type = "text/css">
<!--
@import url("style.css");
-->
</style>
</head>
<body class = "body">
<!-- JavaScript code : Greeting with user name -->
<script language = "javascript">
<!--
askNameGreet();
//-->
</script><!-- date, weekday, season -->
<script language = "javascript">
<!--
today();
</script>
</body>
</html>请问是哪个部份错了呢?我修改了好几次,还是无法在运行网页的时候执行JAVASCRIPT 的 FUNCTION

解决方案 »

  1.   

    楼主的html代码太乱了 html的注释和js的注释混用 完全乱了 楼主把注释的都删了 再传个html上来
      

  2.   

    不好意思,是我刪注释的时候不仔细
    以下是修改后的HTML 代码:<html>
    <head>
    <title>test JavaScript file 2</title>
    <script type = "text/javascript" scr = "scripts/try3.js">
    </script>
    <style type = "text/css">
    <!--
    @import url("style.css");
    -->
    </style>
    </head>
    <body class = "body">
    <script language = "javascript"><!--//a prompt to ask name 
    askNameGreet();//date, weekday, season
    today();//--></script>
    </body>
    </html>
      

  3.   

    问题太多了!!
    1.
    <script type = "text/javascript" src="scripts/try3.js">你写的是scr2.
    function askNameGreet() {
        var name;
        var hour = new Date();
        var hours = hour.getHours();
        name = prompt("Nice to meet you. \May I know your name?", "Peter");
        /*if (hours <= 11) document.write("<font color = "
        green "><b>Good morning!" < /b></font > );
        else if (hours <= 18) document.write("<font color = "
        green "><b>Good afternoon!" < /b></font > );
        else if (hours <= 23) document.write("<font color = "
        green "><b>Good evening!" < /b></font > );
        document.write(" " + < font color = "green" > < b > name < /b></font > );
        */
        //上面几条语句引号不匹配,不要再用font标签了,属性=属性值之前不应该有空格
        if (hours <= 11) document.write('<p style="color:green"><b>Good morning!</b></p>');
        else if (hours <= 18) document.write('<p style="color:green"><b>Good afternoon!</b></p>');
        else if (hours <= 23) document.write('<p style="color:green"><b>Good evening!</b></p>');
        else document.write('<p style="color:green"><b>name</b><p>');
    }3.
    这两个函数你倒底要执行几遍??js文件中有window.onload调用,html文件中又调用。4.window.onload无法加载多个函数:
    window.onload = today();
    window.onload = askNameGreet(); //这一行会覆盖前一行
    如果要调用多个函数,要这么写:
    window.onload = function() {
        today();
        askNameGreet();
    }5+++
    另外还有一大堆问题。
      

  4.   

    <html>
    <head>
    <title>test JavaScript file 2</title>
    <script type = "text/javascript" src = "js/try3.js">
    </script>
    <style type = "text/css">
    <!--
    @import url("style.css");
    -->
    </style>
    </head>
    <body class = "body">
    <!-- JavaScript code : Greeting with user name --></body>
    </html>window.onload = function(){today();askNameGreet();}function askNameGreet(){var name;
    var hour = new Date();
    var hours = hour.getHours();name = prompt ("Nice to meet you. \May I know your name?", "Peter");
    if ( hours <= 11) document.write("<font color = \"green\"><b>Good morning!</b></font>");
    else 
    if ( hours <= 18) document.write("<font color = \"green\"><b>Good afternoon!</b></font>");
    else 
    if ( hours <= 23) document.write("<font color = \"green\"><b>Good evening!</b></font>");
    document.write(" <font color = \"green\"><b>"+name+"</b></font>");}function today(){var season;
    var day = new Date();
    var month = day.getMonth() + 1;
    var date = day.getDate();
    var year = day.getFullYear();
    var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");if (year < 2000) year = year + 1900;
    if (month >= 3 && month <= 4) season = "Spring ";
    if (month >= 5 && month <= 8) season = "Summer ";
    if (month >= 9 && month <= 10) season = "Autume ";
    if (month >= 11 || month <= 2) season = "Winter ";
    document.write("<font color = \"pink\"><b>Today is " + year + " \/ " + month + " \/ " + date + ", " + weekday[day.getDay()] + ", " + "Season is: " + season+"</b></font>");}