直接帖代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script language="javascript" type="text/javascript">
function talk(msg, handler)
{
var len = arguments.length;
//传递过来一个参数的时候执行
var msgType = typeof msg;
if (msgType != "string")
{
alert("您传入的类型为:" + msgType + ",请传入字符串类型的参数!");
return;
}
if (len == 1)
{
alert("Function say:" + msg);
}
//传递过来两个参数的时候执行
else if (len == 2)
{
if (typeof handler == "function")
{
handler(msg);
}
else
{
alert("不是函数");
}
}
}
function ShowMessage()
{
//talk("demo");
talk("demo", function(w) { alert("Handler say:" + w); });
//talk("你好", 225);
//talk(22.2);
}
</script>
</head>
<body>
<input type="button" value="调用" οnclick="ShowMessage();" />
</body>
</html>
谢谢浏览!