源码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery-3.6.0.js"></script>
<style type="text/css">
body {
margin: 0px;
font-size: 14px;
}
#top {
height: 30px;
background-color: azure;
}
#top span {
margin-left: 7px;
line-height: 30px;
float: left;
font-weight: bolder;
margin-right: 7px;
}
#top>ul {
list-style: none;
margin-top: 0px;
margin-bottom: 0px;
float: left;
line-height: 30px;
padding: 0px;
}
#top ul li {
float: left;
margin-left: 7px;
margin-right: 3px;
}
#main {
width: 98%;
margin: 20px auto;
}
#main_top {
border-bottom: 1px solid darkgray;
height: 30px;
position: relative;
}
#main_top span {
font-weight: bolder;
border-bottom: 3px solid #00FFFF;
line-height: 30px;
position: absolute;
bottom: -1px;
}
#main_body form ul {
list-style: none;
}
#main_body form ul li {
margin-top: 15px;
}
label {
display: inline-block;
line-height: 30px;
width: 80px;
text-align: center;
float: left;
}
input[name='userName'],
input[name='pwd'] {
width: 300px;
height: 26px;
border-radius: 5px;
border: 1px solid dimgray;
}
select {
width: 200px;
height: 26px;
border-radius: 5px;
border: 1px solid dimgray;
}
textarea {
width: 400px;
height: 100px;
border-radius: 5px;
border: 1px solid dimgray;
}
input[type="button"]{
width: 100px;
height: 30px;
background-color: #00FFFF;
color: white;
font-weight: bolder;
border: 0px;
border-radius: 5px;
}
input[type='radio'],
input[type='checkbox'] {
margin-top: 10px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
var userName = $(":text").val();
var pwd = $(":password").val();
var sex = $(":radio:checked").val();
var hobby = [];
var i = 0;
$("input[name='hobby']:checked").each(function(){
hobby[i] = $(this).val();
i++;
});
var star = $("#star option:selected").text();
var remark = $("#remark").val();
var result = {};
result.userName = userName;
result.pwd = pwd;
result.sex = sex;
result.hobby = hobby;
result.star = star;
result.remark = remark;
console.log(result);
$("res").html(result);
});
});
</script>
</head>
<body>
<!-- 头 -->
<div id="top">
<span>位置:</span>
<ul>
<li>首页</li>
<li>--></li>
<li>表单</li>
</ul>
</div>
<!-- 主体 -->
<div id="main">
<div id="main_top">
<span>注册信息</span>
</div>
<div id="main_body">
<form method="post">
<ul>
<li>
<label for="userName">账号</label>
<input type="text" id="userName" name="userName" placeholder="请输入账号" />
</li>
<li>
<label for="pwd">密码</label>
<input type="password" id="pwd" name="pwd" placeholder="请输入密码" />
</li>
<li>
<label>性别</label>
<input type="radio" name="sex" value="male" checked />男
<input type="radio" name="sex" value="female" />女
</li>
<li>
<label>爱好</label>
<input type="checkbox" name="hobby" value="basketball" />篮球
<input type="checkbox" name="hobby" value="football" />足球
<input type="checkbox" name="hobby" value="pingpang" />兵乓球
</li>
<li>
<label>星座</label>
<select name="star" id="star">
<option value="1">白羊座</option>
<option value="2">水瓶座</option>
<option value="3">射手座</option>
</select>
</li>
<li>
<label>备注</label>
<textarea name="remark" id="remark"></textarea>
</li>
<li>
<label> </label>
<input id="btn" type="button" name="sumbit" value="注 册"/>
</li>
</ul>
</form>
<p id="res"></p>
</div>
</div>
</body>
</html>
运行结果如下: