enter
text
<input id="nickname" type="text" placeholder="请输入昵称">
password
<input id="password" type="password" placeholder="请输入密码">
Single box
<input class="sex" checked type="radio" name="sex" value="0"><span class="sexname">男</span>
<input class="sex" type="radio" name="sex" value="1"><span class="sexname">女</span>
mailbox
<input id="email" type="email" placeholder="请输入邮箱">
js get parameters
Here is an example of fields commonly used by registered users
$(function () {
}
$("#submit").click(function () {
}
Get value
let nickname = $("#nickname").val();
let username = $("#username").val();
let psd = $("#password").val();
let c_psd = $("#confirm_password").val();
let email = $("#email").val();
// 单选框 性别
let sex = $("input:radio[name='sex']:checked").val();
let phone = $("#phone").val();
if (uname == '' || psd == '' || c_psd == '' || nickname == '') {
message.showError("昵称、用户名或密码不能为空!!!");
} else if (psd != c_psd) {
message.showError("密码不一致!!!");
} else {
message.showSuccess('注册成功!!!')
$.ajax({
url: '/register',
type: 'POST',
dataType: 'json',
data: {
'nickname': nickname,
'username': uname,
'password': psd,
'confirm_password': c_psd,
'sex': sex,
'phone': phone,
'email': email,
},
success: function (res) {
if (res.data == 200) {
message.showSuccess('注册成功')
location.href = '/'
} else if (res.data == 403){
message.showError('该账号已注册!!!');
}else if (res.data == 0){
message.showError('密码不一致!!!');
}else{
message.showError(res.info);
}
},
error: function () {
message.showError('服务器超时,请重试!');
}
});
}