<html>
<head>
<meta charset="UTF-8">
<title>html_js</title>
</head>
<body>
<!-- html_js的第一种结合方式 -->
<script type="text/javascript">
/* js代码 */
</script>
<!-- html_js的第二种结合方式 -->
<!--不要再标签中写代码不显示 -->
<!--9*9乘法表 -->
<script type="text/javascript" src="1.js">
</script>
</body>
</html>
//js文件
document.write("JS中==比较的是变量的类型,===比较的是值和类型");
document.write("<br>");
var a = 123;
var b = "123"
if (a == b) {
document.write("true");
} else {
document.write("false");
}
document.write("<hr size='5' color='red'>");
if (a === b) {
document.write("true");
} else {
document.write("false");
}
document.write("<hr size='5' color='red'>");
document.write("乘法表");
document.write("<br>");
for (var i = 1; i < 10; i++) {
for (var j = 1; j <= i; j++) {
document.write(j + "x" + i + "=" + (i * j) + " ");
}
document.write("<br>");
}
document.write("<hr size='5' color='red'>");
document.write("<table border='1' bordercolor='black' cellspacing='0'>");
for (var i = 1; i < 10; i++) {
document.write("<tr>");
for (var j = 1; j <= i; j++) {
document.write("<td>");
document.write(j + "x" + i + "=" + (i * j));
document.write("</td>");
}
document.write("</tr>");
}
document.write("</table>");
document.write("<hr size='5' color='red'>");
document.write("数组");
document.write("<br>");
var arr_a = [ 1, 2, 3 ];
var arr_b = new Array(3);
arr_b[0] = "4";
arr_b[1] = ""5"";
arr_b[2] = 6;
var arr_c = new Array(""7"", "8", "9");
document.write(arr_a);
document.write("<br>");
document.write(arr_b);
document.write("<br>");
document.write(arr_c);
document.write("<hr size='5' color='red'>");
document.write("函数");
document.write("<br>");
// 无参,无返回值
function test_1() {
document.write("我");
}
test_1();
document.write("<br>");
// 有参,无返回值
function test_2(a, b) {
document.write(a + b);
}
test_2(1, 1);
document.write("<br>");
// 有参,有返回值
function test_3(a, b) {
return a + b;
}
document.write(test_3(1, 2));
document.write("<br>");
document.write("匿名函数");
document.write("<br>");
var c = function(a, b) {
document.write(a + b);
}
c(1, 3);
document.write("<br>");