添加頁面
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Add</title>
<script src="~/Content/jquery-3.1.1.js"></script>
@*驗證碼類*@
<script src="~/Content/yzmJS.js"></script>
@*驗證碼樣式*@
<link href="~/Content/yzmStyle.css" rel="stylesheet" />
@*布局樣式*@
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
.login {
margin-left: 450px;
margin-top: 170px;
}
ul {
list-style: none;
}
li {
margin-bottom: 10px;
}
li .bt {
color: red;
}
li .zi {
color: #666;
}
.txtAdd {
width: 285px;
height: 35px;
border: 1px solid aquamarine;
}
.ty {
font-size: 12px;
margin-top: 20px;
margin-left: 90px;
}
.btnAdd {
width: 285px;
height: 35px;
background-color: red;
border: 1px solid red;
color: white;
margin-top: 10px;
margin-left: 90px;
}
.txtAddYZ {
width: 150px;
height: 35px;
border: 1px solid aquamarine;
}
.tp {
width: 80px;
height: 35px;
}
.yz {
font-size: 12px;
}
#spName {
color:red;
font-size:12px;
}
#spPwd0 {
color: red;
font-size: 12px;
}
#ckTong {
color: red;
font-size: 12px;
}
#spYan {
color: red;
font-size: 12px;
margin-left:8px;
}
</style>
</head>
<body>
<form id="FormAdd">
<div class="login">
<ul>
<li>
<span class="bt">*</span>
<samp class="zi"> 用戶名</samp>:
<input class="txtAdd" id="Text1" type="text" name="UserName" />
<span id="spName"></span>
</li>
<li>
<span class="bt">*</span>
<samp class="zi"> 請設置密碼</samp>:
<input class="txtAdd" type="password" name="UserPassword" />
<span id="spPwd"></span>
</li>
<li>
<span class="bt">*</span>
<samp class="zi"> 請確認密碼</samp>:
<input class="txtAdd" type="password" name="pwd0" />
<span id="spPwd0"></span>
</li>
<li>
<span class="bt">*</span>
<samp class="zi"> 驗證碼</samp>:
<input class="txtAddYZ" type="text" id="yanz" />
<input type="button" id="code" onclick="createCode()" class="tp" />
<a href="javascript:void(0)" onclick="createCode()" class="yz">看不清,再換一張</a><span id="spYan"></span>
</li>
<li class="ty">
<input id="Checkbox1" type="checkbox" name="ck" />
我已閱讀並同意<a href="#">《金象網用戶註冊協議》</a>
<span id="ckTong"></span>
</li>
</ul>
<input id="Button1" class="btnAdd" type="button" value="立即註冊" onclick="Add()"/>
</div>
</form>
</body>
</html>
<script>
$(function () {
//獲取焦點
$("input").focus();
//用戶名文本框失去焦點
$("[name=UserName]").blur(function () {
$.ajax({
url: "/Login/GetUser?Name=" + $("[name=UserName]").val(),
type: "post",
success: function (d) {
console.log(d)
if (d ==1) {
$("#spName").html("用戶名以存在")
}
else {
$("#spName").html("")
}
}
})
})
//確認密碼框失去焦點
$("[name=pwd0]").blur(function () {
if ($("[name=pwd0]").val() != $("[name=UserPassword]").val()) {
$("#spPwd0").html("兩次密碼輸入不一致");
}
else {
$("#spPwd0").html("")
}
})
})
//驗證碼,協議驗證 加上添加
function Add() {
var oValue = $("#yanz").val().toUpperCase();
console.log(oValue);
if (oValue == 0) {
$("#spYan").html("請輸入驗證碼")
}
else if (oValue != code) {
$("#spYan").html("驗證碼不正確")
}
else {
$("#spYan").html("")
}
if (!$("#Checkbox1").prop("checked")) {
$("#ckTong").html("尚未同意協議")
return
}
else {
$.ajax({
url: "/Login/Add",
type: "post",
data: $("#FormAdd").serialize(),
success: function (data) {
if (data > 0) {
alert("註冊成功")
location.href="/Login/Login"
}
}
})
}
}
</script>
添加頁面