<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
</script>
</head>
<body>
<script type="text/javascript">
function blue(agrs){
var out = "";
if(typeof agrs.name == "String"){
out += "Name:" + agrs.name + "\n";
}
if(typeof agrs.age == "Number"){
out += "Age:" + agrs.age + "\n";
}
alert(out);
}
blue({
name:"blue";
age:22;
})
</script>
</body>
</html>
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
</script>
</head>
<body>
<script type="text/javascript">
function blue(agrs){
var out = "";
if(typeof agrs.name == "String"){
out += "Name:" + agrs.name + "\n";
}
if(typeof agrs.age == "Number"){
out += "Age:" + agrs.age + "\n";
}
alert(out);
}
blue({
name:"blue";
age:22;
})
</script>
</body>
</html>
function blue(agrs){
var out = "";
if(typeof agrs.name == "string"){
out += "Name:" + agrs.name + "\n";
}
if(typeof agrs.age == "number"){
out += "Age:" + agrs.age + "\n";
}
alert(out);
}
blue({
name:"blue",
age:22
})
var out = ""; if(agrs.name.constructor == String){
out += "Name:" + agrs.name + "\n";
}
if(agrs.age.constructor == Number){
out += "Age:" + agrs.age + "\n";
}
alert(out);
}
blue({
name:"blue",
age:22
})
仔细对照下typeof使用的时候要小心 不是不行。而是注意大小写