Function

種類オブジェクト
書式
function 関数名(引数)
{
処理内容
}
解説
関数を定義します。引数は省略することができます。また、引数は,(カンマ)で区切って列記することができます。関数の処理結果を呼び出し元に返したい場合にはreturn命令を使います。
サンプルコード
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<style type="text/css"><!--
body { margin:0px; }
form { position:absolute; top:10;left:10px; }
--></style>
<script type="text/javascript"><!--
function getSec()
{
var dObj = new Date();
var n = dObj.getSeconds();
return n.toString();
}
window.onload = function()
{
n = arguments.length;
document.getElementById("txtField").value = getSec();
}
// --></script>
</head>
<body>
<img src="Default.png">
<form>
<input type="text" id="txtField" size=40"><br>
</form>
</body>
</html>
実際のスクリプトをダウンロード