用javascript做出这道题

用javascript做出这道题要全部代码
2025-05-19 23:19:53
推荐回答(1个)
回答1:









* {font-family: "微软雅黑";padding: 0;margin: 0;}
label {padding: 5px 0 5px 0;display: inline-block;}
input[type=radio],input[type=checkbox] {width: 15px;height: 15px;}
button{width: 70px;height: 30px;}
body>div:first-child{padding: 10px;}












足球
拉球
排球



专业一
专业二
专业三
专业四

头发特长

头发特长
提交
重置







$('#submit').click(function(){
//序列化表单
var form = $('#form').serializeObject();
//表单转化为对象
form.accessory = $('input[name="accessory"]').val()
console.log(form);
//验证密码
if(form.psd != '123'){
alert('密码错误,请检查!');
return false;
}
//拼接需求的格式
var html = '姓名:'+form.username+'\n'+
   '密码:'+form.psd+'\n'+
   '性别:'+form.sex+'\n'+
   '爱好:'+form.hobby+'\n'+
   '专业:'+form.major+'\n'+
   '特长:'+form.speciality+'\n'+
   '附件:'+form.accessory+'\n'+
   '简介:'+form.synopsis+'\n';
alert(html);
})
//表单提交数据转为object类型
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if(o[this.name]) {
if(!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}