<html>
<head>
<script type="text/javascript">
function myfunction()
{
return("welcome to china!")
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(myfunction())
</script>
<body>
</html>
例2
<html>
<head>
<script type="text/javascript">
function total(numberA,numberB)
{
return numberA + numberB
}
</script>
</head>
<body>
<script type="text/javascript">
document.write(total(2,3))
</script>
<body>
</html>
本文通过两个具体实例展示了如何在HTML页面中使用JavaScript编写简单的函数。第一个例子演示了如何定义并调用一个欢迎信息显示函数;第二个例子则介绍了如何创建并利用一个函数来计算两个数的总和。
2431

被折叠的 条评论
为什么被折叠?



