添加相关信息
由于没有规定添加的相关的内容,所以这里我写的是书籍添加信息:
<!DOCTYPE html>
<html>
<head lang="en">
<?php
//创建session
session_start();
//在session中保存一个令牌token数据
$_SESSION['token']=md5(time().'lovo');
?>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="jquery-ui-1.10.1.custom.min.css"/>
<style>
.text{
width: 180px;
}
form{
border: 1px solid lightgray;
width: 480px;
margin: 0 auto;
padding: 10px;
}
</style>
<script src="js/jquery-1.12.2.min.js"></script>
<script src="js/jquery-ui-1.10.1.custom.js"></script>
</head>
<body>
<form action="newbook.php" method="post" enctype="multipart/form-data" onsubmit="return chkform()" >
<p>
书籍名称: <input type="text" class="text" name="bname"/>
</p>
<p>
书籍类别: <select name="" class="text" id="">
<option value="1">类别1</option>
<option value="2">类别2</option>
<option value="3">类别3</option>
</select>
</p>
<p>
书籍图片: <input type="file" class="text" name="bpic"/>
</p>
<p>
<span style="letter-spacing: 2em;">作</span>者: <input type="text" class="text" name="bauthor"/>
</p>
<p>
<span style="letter-spacing: .5em;">出版</span>社: <input type="text" class="text" name="bpublisher"/>
</p>
<p>
<span style="letter-spacing: .5em;">出版</span>号: <input type="text" class="text" name="bcsbn"/>
</p>
<p>
出版日期: <input type="text" id="chudate" class="text" name="bdate"/>
</p>
<p>
<span style="letter-spacing: 2em;">价</span>格: <input type="text" class="text" name="bprice"/>
</p>
<p>
现货数量: <input type="text" class="text" name="bnum"/>
</p>
<p style="overflow: hidden;">
<span style="float: left;">书籍描述: </span>
<textarea style="margin-left: 9px;resize: none;" name="bdesc" class="text" rows="6"></textarea>
</p>
<p>
<input type="submit" style="font-size: 18px;" value=" 添 加 "/>
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>"/>
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
</p>
</form>
<script>
$("#chudate").datepicker({
dateFormat: "yy-mm-dd",
changeMonth: true,
changeYear: true,
monthNames: [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" ],
monthNamesShort: [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" ],
dayNamesMin: [ "日", "一", "二", "三", "四", "五", "六" ],
dayNames: [ "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" ]
});
$("#ui-datepicker-div").css("font-size","10px");
var myinput=$("form:eq(0) :input");
function mychk(reg, errinfo, obj){
$(obj).next('span').remove();
if(reg.test($(obj).val())){
return true;
}else{
$(obj).after("<span style='color:red;font-size: 10px;'>"+errinfo+"</span>")
return false;
}
}
function mychknum(errinfo, obj){
$(obj).next('span').remove();
if($(obj).val().trim()=="" || isNaN($(obj).val())){
$(obj).after("<span style='color:red;font-size: 10px;'>"+errinfo+"</span>")
return false;
}else{
return true;
}
}
myinput.eq(0).blur(function(){mychk(/^.+$/, '书籍名称必须要有', this);});
myinput.eq(1).blur(function(){mychk(/^.+$/, '书籍封面一定要有', this)});
myinput.eq(2).blur(function(){mychk(/^.+$/, '没有作者信息', this)});
myinput.eq(3).blur(function(){mychk(/^.+$/, '必须有出版社名称', this)});
myinput.eq(4).blur(function(){mychk(/^.+$/, '必须有书籍出版号', this)});
myinput.eq(5).blur(function(){mychk(/^.+$/, '必须有出版日期', this)});
myinput.eq(6).blur(function(){mychknum('价格必须是数字', this)});
myinput.eq(7).blur(function(){mychknum('库存数量必须是数字', this)});
myinput.eq(8).blur(function(){mychk(/^.+$/, '必须有书籍描述', this)});
function chkform(){
myinput.each(function(){
$(this).blur();
});
if($("form:eq(0) :input+span").length == 0)
return true;
return false;
}
</script>
</body>
</html>