#javascript打印输出 ##输出方法 window.alert() 弹窗打印 <!DOCTYPE html> <html lang="
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>