javascript输出

前端开发 作者: 2024-08-26 07:20:01
#javascript打印输出 ##输出方法 window.alert() 弹窗打印 <!DOCTYPE html> <html lang=&quot

javascript打印输出

  1. 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>
  1. 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>
  1. 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>
  1. 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>
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68845.html
javascript输出