javascript输出
javascript打印输出
输出方法
- window.alert() 弹窗打印
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>空白</title>
</head>
<body>
<p id="tx">你是谁? </p>
<script>
function my(){
alert("你到底是谁呢?")
}
</script>
<button type="button" onclick="my()">点击我试试</button>
</body>
</html>
- document.write() 写入HTML文档
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>空白</title>
</head>
<body>
<p id="tx">你是谁? </p>
<script>
function my(){
document.write('你是万能的神!')
}
</script>
<button type="button" onclick="my()">点击我试试</button>
</body>
</html>
- innerHTML 写入HTML元素
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>空白</title>
</head>
<body>
<p id="tx">你是谁? </p>
<script>
function my(){
document.getElementById('tx').innerHTML="你是救世主!"
}
</script>
<button type="button" onclick="my()">点击我试试</button>
</body>
</html>
- console.log() 控制台打印
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>空白</title>
</head>
<body>
<p id="tx">你是谁? </p>
<script>
function my(){
console.log('你是万能的神!')
}
</script>
<button type="button" onclick="my()">点击我试试</button>
</body>
</html>
通过以上打印进行测试代码执行是否正确。
本文来自博客园,作者:Harry_666,转载请注明原文链接:https://www.cnblogs.com/harry66/p/13532668.html