同一个页面内实现html+js表单提交输出功能

<html>
<head>
<title>同一个页面内实现html+js表单提交输出功能</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style>
	<!--
	.b{
		position:absolute;
		left:0;
		top:0;
		width:200px;
		height:100px;
		color:#fff;
		background:#000;
	}
	-->
</style>
</head>

<body>
	<div id="d2">
		<form name="myform" action="#">
			name:<input type="text" name="name">
			age:<input type="text" name="age">
			<input type="button" id="but" value="ok";>
		</form>
	</div>
	<div id="d1" class="b" style="display:none;">asdf</div>
</body>
<script>
	function aaaaa(){
		var name=document.myform.name.value;

		var age=document.myform.age.value;
		document.getElementById("d1").style.display="";
		document.getElementById("d2").style.display="none";
		document.getElementById("d1").innerHTML="name:"+name+"<br>age:"+age;
	}
	document.getElementById("but").onclick = aaaaa;
</script>
</html>

点击前:

点击后:

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的注册页面HTML、CSS、和JavaScript代码: HTML代码: ```html <!DOCTYPE html> <html> <head> <title>注册页面</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <form id="register-form" method="POST"> <h1>注册</h1> <label for="username">用户名</label> <input type="text" id="username" name="username" required> <label for="email">邮箱</label> <input type="email" id="email" name="email" required> <label for="password">密码</label> <input type="password" id="password" name="password" minlength="8" required> <label for="confirm-password">确认密码</label> <input type="password" id="confirm-password" name="confirm-password" minlength="8" required> <button type="submit">注册</button> </form> <script src="script.js"></script> </body> </html> ``` CSS代码: ```css body { font-family: Arial, sans-serif; background-color: #f2f2f2; } form { background-color: #ffffff; max-width: 400px; margin: 0 auto; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { text-align: center; } label { display: block; margin-top: 10px; } input[type="text"], input[type="email"], input[type="password"] { width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button[type="submit"] { background-color: #4CAF50; color: #ffffff; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; width: 100%; margin-top: 20px; } button[type="submit"]:hover { background-color: #45a049; } ``` JavaScript代码: ```javascript const form = document.getElementById('register-form'); const usernameInput = document.getElementById('username'); const emailInput = document.getElementById('email'); const passwordInput = document.getElementById('password'); const confirmPasswordInput = document.getElementById('confirm-password'); form.addEventListener('submit', (event) => { event.preventDefault(); if (passwordInput.value !== confirmPasswordInput.value) { alert('密码不一致,请重新输入!'); return; } const formData = new FormData(event.target); const formDataJSON = Object.fromEntries(formData.entries()); console.log(formDataJSON); // 在这里添加将数据发送到服务器的代码 }); ``` 这是一个基础的注册页面,包含了用户名、邮箱、密码和确认密码的输入框,以及一个注册按钮。JavaScript代码添加了一个表单提交事件监听器,用于在表单提交时验证密码是否一致并发送表单数据。当表单提交时,将会将表单数据转换为JSON对象,并输出到控制台上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值