流程控制之九九乘法表
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>流程控制之九乘九乘法表-for循环</title>
</head>
<script>
document.write("<table border='1px' >")
for(var i = 1; i <= 9; i++){
document.write("<tr>")
for(var j = 1; j <= 9; j++){
if(j>i){
document.write("<td> </td>");
}else{
document.write("<td>")
document.write("" + i + "*" + j + "=" + (i*j) + "")
document.write("</td>")
}
}
document.write("</tr>")
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px' >")
for(var i = 9; i >= 1; i--){
document.write("<tr>")
for(var j = 1; j <= 9; j++){
if(j>i){
document.write("<td> </td>");
}else{
document.write("<td>")
document.write("" + i + "*" + j + "=" + (i*j) + "")
document.write("</td>")
}
}
document.write("</tr>")
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px' >")
for(var i = 9; i >= 1; i--){
document.write("<tr>")
for(var j = 9; j >= 1; j--){
if(j>i){
document.write("<td> </td>");
}else{
document.write("<td>")
document.write("" + i + "*" + j + "=" + (i*j) + "")
document.write("</td>")
}
}
document.write("</tr>")
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px' >")
for(var i = 1; i <= 9; i++){
document.write("<tr>")
for(var j = 9; j >= 1; j--){
if(j>i){
document.write("<td> </td>");
}else{
document.write("<td>")
document.write("" + i + "*" + j + "=" + (i*j) + "")
document.write("</td>")
}
}
document.write("</tr>")
}
document.write("</table>")
document.write("<br/><hr/><br/>")
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>流程控制之九九乘法表-while</title>
</head>
<script>
document.write("<table border='1px'> ")
var i =1;
while(i<=9){
document.write("<tr>")
var j=1;
while(j<=9){
if(j>i){
document.write("<td> </td>")
}else{
document.write("<td>" + i + '*' + j + '=' + (i*j) + "</td>")
}
j++;
}
document.write("</tr>")
i++;
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px'> ")
var i =9;
while(i>=1){
document.write("<tr>")
var j=1;
while(j<=9){
if(j>i){
document.write("<td> </td>")
}else{
document.write("<td>" + i + '*' + j + '=' + (i*j) + "</td>")
}
j++;
}
document.write("</tr>")
i--;
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px'> ")
var i =9;
while(i>=1){
document.write("<tr>")
var j=9;
while(j>=1){
if(j>i){
document.write("<td> </td>")
}else{
document.write("<td>" + i + '*' + j + '=' + (i*j) + "</td>")
}
j--;
}
document.write("</tr>")
i--;
}
document.write("</table>")
document.write("<br/><hr/><br/>")
document.write("<table border='1px'> ")
var i =1;
while(i<=9){
document.write("<tr>")
var j=9;
while(j>=1){
if(j>i){
document.write("<td> </td>")
}else{
document.write("<td>" + i + '*' + j + '=' + (i*j) + "</td>")
}
j--;
}
document.write("</tr>")
i++;
}
document.write("</table>")
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>流程控制之九乘九乘法表-do-while</title>
</head>
<script>
document.write('<table border="1px"> ')
var i=1;
do{
document.write('<tr>')
var j=1;
do{
if(j>i){
document.write('<td> </td>');
}else{
document.write('<td>' + i + '*' + j + '=' + (i*j) + '</td>');
}
j++;
}while(j<=9)
document.write('</tr>')
i++;
}while(i<=9)
document.write('</table>')
document.write('<br/><hr/><br/>')
document.write('<table border="1px"> ')
var i=9;
do{
document.write('<tr>')
var j=1;
do{
if(j>i){
document.write('<td> </td>');
}else{
document.write('<td>' + i + '*' + j + '=' + (i*j) + '</td>');
}
j++;
}while(j<=9)
document.write('</tr>')
i--;
}while(i>=1)
document.write('</table>')
document.write('<br/><hr/><br/>')
document.write('<table border="1px"> ')
var i=9;
do{
document.write('<tr>')
var j=9;
do{
if(j>i){
document.write('<td> </td>');
}else{
document.write('<td>' + i + '*' + j + '=' + (i*j) + '</td>');
}
j--;
}while(j>=1)
document.write('</tr>')
i--;
}while(i>=1)
document.write('</table>')
document.write('<br/><hr/><br/>')
document.write('<table border="1px"> ')
var i=1;
do{
document.write('<tr>')
var j=9;
do{
if(j>i){
document.write('<td> </td>');
}else{
document.write('<td>' + i + '*' + j + '=' + (i*j) + '</td>');
}
j--;
}while(j>=1)
document.write('</tr>')
i++;
}while(i<=9)
document.write('</table>')
document.write('<br/><hr/><br/>')
</script>
<body>
</body>
</html>
函数
函数的定义方式和使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>函数的定义方式即使用</title>
</head>
<script>
var num=0;
function add(a, b){
num=a+b;
return num;
}
var a=add(1,2);
console.log(a)
var add1 = new Function("a","b","return a+b;");
var b = add1(1,3);
console.log(b);
var add2 = function(a,b){return a+b;}
var c = add2(1,4);
console.log(c)
</script>
<body>
</body>
</html>
函数arguments对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>srgumrnts 对象</title>
</head>
<script>
var a;
function select(a){
if(arguments[0] == 'hi'){
console.log('你好!')
}else if(arguments[0] == 'doing'){
console.log('正在讲述内容...')
}else if(arguments[0] == 'bye'){
console.log('再见!')
}else{
console.log('输入有误,请重新输入!')
}
}
select('hi');
select('doing');
select('bye');
select('a');
console.log('========================================')
function howLong(){
alert(arguments.length)
}
howLong();
howLong(1,2);
howLong("2");
</script>
<body>
</body>
</html>
函数的内置函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>系统中的内置函数</title>
</head>
<script>
var a = "http://www.baidu.com ",b="?()#&";
console.log(escape(a));
console.log(escape(b));
var x = escape(a)
var y = escape(b)
console.log(unescape(x));
console.log(unescape(y));
var a = "document.write('a')";
eval(a)
var a = 1,b="a",c="1";
console.log(isNaN(a));
console.log(isNaN(b));
console.log(isNaN(c));
var x = "123abc",y= "123.1abc";
console.log(parseInt(x));
console.log(parseFloat(y));
</script>
<body>
</body>
</html>