03.js输出数据的几种方式
程序员文章站
2024-03-17 16:25:58
...
1.window,alert():弹出警告框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
window.alert(1+1);
</script>
</body>
</html>
2.document.write()
将内容写到HTML中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
document.write("你好");
</script>
</body>
</html>
3.innerHTML
写入到HTML元素中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p id="demo">你好</p>
<script>
document.getElementById("demo").innerHTML="修改完毕!";
</script>
</body>
</html>
4.console.log():写入到浏览器的控制台
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
a = 1;
b = 2;
c = a + b;
console.log(c);
</script>
</body>
</html>
上一篇: C++面向对象——构造函数与析构函数、内存分区模型
下一篇: 输入输出外挂