gpt4 book ai didi

javascript - 具有适当参数的函数

转载 作者:行者123 更新时间:2023-11-28 16:33:28 25 4
gpt4 key购买 nike

大家好,我还有一个问题。我现在正在处理函数和事件,这就是我到目前为止所拥有的..

   <!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”(但我很确定这是用于按钮的)。我也知道我可以使用数组,但我不知道这是否有效。

最佳答案

你有几个错误..

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”错误拼写为“Personal”。

更新:在您的第二个 <script> 中 block ,您的评论 block 标签不正确:/ *不应有空格。这是正确的:/*

关于javascript - 具有适当参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com