2011-02-09 44 views
0

大家好我有更多的問題。我現在用的職能和活動的工作,這是我迄今爲止..具有適當參數的函數

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>Personal Information</title> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" href="js_styles.css" type="text/css" /> 
    <script type="text/javascript"> 
    //<![CDATA[ 
    function printPeronalinfo("name,age,hobbies,favorite movies") { 
    document.write("<p>" + name +"</p>"); 
    document.write("<p>" + age +"</p>"); 
    document.write("<p>" + hobbies + "</p>"); 
    document.write("<p>" + favorite video + "</p>"); 
    } 
    //]]> 
    </script> 
    </head> 
    <body> 
    <script type="text/javascript"> 
    /* <![CDATA[ */ 
    printPeronalinfo("age,age,hobbies,favorite movies") 
    var return_value = return_message(); 
    document.write(return_value); 
    /*]]> */ 

    </script> 
    </body> 
    </html> 

現在我的問題是,我知道我做錯了什麼原因它沒有顯示在網頁上了。這是想讀我的名字,年齡,愛好,最喜歡的電影。現在,我要重複頭腦中的內容,而不是單詞名稱,我將把名字放在那裏,或者使用if或else(但我確定這是按鈕)。我也知道我可以使用一個數組,但我不知道這是否會起作用。

回答

2

你有幾個錯誤..

function printPeronalinfo("name,age,hobbies,favorite movies") { 
/*      ^no quotes here,^invalid variable name */ 
// should be: function printPeronalinfo(name, age, hobbies, favorite_movies) { 
    document.write("<p>" + name +"</p>"); 
    document.write("<p>" + age +"</p>"); 
    document.write("<p>" + hobbies + "</p>"); 
    document.write("<p>" + favorite video + "</p>"); 
    /*     ^undefined variable, isn't defined in your function */ 
    // should be: document.write("<p>" + favorite_movies + "</p>"); 
} 

...

printPeronalinfo("age,age,hobbies,favorite movies"); 
/*    ^incorrect passing of data */ 
// should be: printPeronalinfo("name", "age", "hobbies", "favorite movies"); 

您還應該意識到,您的函數名稱將「Personal」拼錯爲「Peronal」。

更新:在你的第二塊<script>,你有一個不正確的註釋塊用標籤:/ *不應該有一個空間。這是正確的:/*

+0

好吧,我得到它的工作,除了電影之一不工作.. – norris1023

+0

在我的工作完全正常。 – drudge

+0

好的,謝謝你,你可以提供一些關於如何創造性的想法。你認爲窗口提示會好嗎 – norris1023

2

從周圍的功能參數刪除引號:

function printPeronalinfo(name,age,hobbies,favoritemovies) 

然後調用該函數是這樣的:

printPeronalinfo("name","age","hobbies","favorite movies") 
+0

好吧,我做到了,但沒有任何東西仍然出現。我知道這是簡單的我只是想弄明白。 – norris1023

+0

最喜歡的電影參數名稱中不得有任何空格,比如favoriteMovies – derek

+0

ummm我認爲這會稍微簡單一些,但我猜不是。現在我需要使用var將它們放入separte中。 – norris1023