js代码在标签属性中
详细代码:
<html>
<head>
<title> - - 、</title>
</head>
<body>
<input type="button" value="输出" onclick="console.log('jf');">
</body>
</html>
运行结果:
js代码在<script>标签中
详细代码:
<html>
<head>
<title> - - 、</title>
</head>
<body>
<input type="button" value="输出" onclick="console.log('jf');">
<script>console.log('I am jf')</script>
</body>
</html>
运行结果:
js代码在单独文件中:
详细代码:
<html>
<head>
<title> - - 、</title>
</head>
<body>
<input type="button" value="输出" onclick="console.log('jf');">
<script>console.log('I am jf')</script>
<script src="../js/text.js"></script>
</body>
</html>
运行结果:
循环1:while
详细代码:
var i = 0;
var l = 0;
while (i <= 100){
l = l + i;
i ++;
}
console.log(l);
运行结果:
-
do while 循环
详细代码:
var i = 0;
var l = 0;
do {
l = l +i;
i ++;
}while (i <= 200)
console.log(l);
运行结果:
for循环:
详细代码:
var l = 0;
for (i = 0; i <=6666666; i++ ){
l = l + i;
}
console.log(l)
运行结果:
九九乘法
详细代码:
</script>
<table border = 2>
<script>
for (var i = 1; i <= 9; i ++){
document.write("<tr>")
for (var l = 1; l <= i; l ++){
document.write("<td>" + l + "*" + i + "=" + i*l + "</td>");
}
document.write("</tr>");
}
</script>
运行结果: