javascript小记2 2010/10/04
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>in&&instanceof</title>
<script language="javascript">
function objTest(obj)
{
var i,t,s="";
t=new Array();
t["Date"]=Date;
t["Object"]=Object;
t["Array"]=Array;
for(i in t)//判断i是否包含于t,如果是返回true否则返回false
{
if(obj instanceof t[i])//判断obj是否包含于t[i]类中,如果是返回true否则返回false
{
s+="OBJ is an instanceof"+i+"\n"+"<br/>";
}
else
{
s+="OBJ is not an instanceof"+i+"\n"+"<br/>";
}
}
return(s);
}
var obj=new Date();
document.writeln(objTest(obj));
</script>
</head>
<body>
</body>
</html>
&&运算符
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>&&运算的使用</title>
</head>
<body>
<script type="text/javascript">
var num1=1,num2=2;
document.write(num1<1&&(num2=3),"<br/>",num2);//输出的结果num2为2,因为但第一个表达式(num1<1)为false时
//直接返回false,不运行第二个表达式
</script>
</body>
</html>
||运算符
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>||运算的使用</title>
</head>
<body>
<script type="text/javascript">
var num1=1,num2=2;
document.write(num1>0||(num2=3),"<br/>",num2);//输出的结果num2为2,因为但第一个表达式(num1>0)为true时
//直接返回true,不运行第二个表达式
</script>
</body>
</html>
右移运算符>>
右移运算符会舍弃右边移出的位,而填补左边移出的位由原操作符的符号决定,且总于原操作符保持一致。如果原操作符为正,就用0来填补高位;如果原操作符为负,就用1来填补高位
无符号右移运算符>>>
与右移运算符的不同之处是高位用0来填补
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>9*9乘法表</title>
</head>
<body>
<script type="text/javascript">
var i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
{
if(j>1)document.write("\t");
document.write(j+"*"+i+"="+j*i);
}
document.write("<br>");
}
</script>
</body>
</html>