老师要不帮我看看代码吧,乱码解决不了,而且这个表单提交的onsubmit总是不触发我的js
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="UTF-8">
<title>新建图书信息</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/add.css">
<script type="text/javascript" src="js\addBook.js"></script>
<script type="text/javascript" src="js\jquery-3.6.0.min.js"></script>
</head>
<body>
<script type="text/javascript">
function checksSubmit(){
var a = checkId('#bookId');
var b = checkEmpty('#bookName');
var c= checkPrice('#bookPrice');
var d = checkEmpty('#remarks');
var e = checkPreview('#bookPic');
alert("a="+a);
if(a&&b&&c&&d&&e){
alert(1111);
return true
}
alert("提交不成功");
return false;
}
</script >
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/dept/list.do">
图书信息管理
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, XXX!</h1>
<p>请小心地新增图书信息,要是建了一个错误的就不好了。。。</p>
</div>
<div class="page-header">
<h3><small>新建</small></h3>
</div>
<form class="form-horizontal" action="/controller?method=updateBook" method="post" enctype="multipart/form-data"
onsubmit = "return checksSubmit()">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书编号 :</label>
<div class="col-sm-8">
<input name="bookId" class="form-control" id="bookId">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">图书名称 :</label>
<div class="col-sm-8">
<input name="bookName" class="form-control" id="bookName">
</div>
</div>
<div class="form-group">
<label for="categoryId" class="col-sm-2 control-label">分类 :</label>
<select id="categoryId" name="categoryId" class="col-sm-2 form-control" style="width: auto;margin-left: 15px">
<option value="ca0001" selected="">计算机</option>
<option value="ca0002">文学</option>
<option value="ca0003">历史</option>
<!-- 下拉列表的内容要从分类中进行读取,value值是分类id -->
</select>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">价格 :</label>
<div class="col-sm-8">
<input name="bookPrice" class="form-control" id="bookPrice">
</div>
</div>
<div class="form-group" >
<label for="name" class="col-sm-2 control-label">图书封面 :</label>
<input type="file" id="bookPic" name="bookPic" style="padding-left: 15px">
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">备注 :</label>
<div class="col-sm-8">
<input name="remarks" class="form-control" id="remarks">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</div>
</form>
</div>
<footer class="text-center" >
copy@imooc
</footer>
</body>
</html>
function checkEmpty(input){
var value = $(input).val();
if($.trim(value) == ""){
$(input).value("请输入内容");
return false;
}
return true;
}
function checkPrice(input){
var reg = /^[1-9][0-9]{1,4}$/;
var val = $(input).val();
if(checkEmpty(input)){
if(reg.test(val)){
return true;
}
}
alert("价格只能是数字组成,或者你输入的价格太高了");
return false;
}
function checkPreview(input){
var val = $(input).val().toLowerCase();
var last = val.substring(val.length-3);
if(checkEmpty(input)){
if(last=="png" || last=="jpg" || last=="gif"){
return true;
}
}
alert("上传的文件格式不对,应该为jpg,png,gif类型");
return false;
}
function changePreview(input){
var val = $(input).val().toLowerCase();
var last = val.substring(val.length-3);
if(last=="png" || last=="jpg" || last=="gif" || val==null){
return true;
}
alert("上传的文件格式不对,应该为jpg,png,gif类型");
return false;
}
function checkId(input){
var reg = /^[a-z][a-z][0-9]*4$/;
var val = $(input).val();
if(checkEmpty){
if(reg.test(val)){
return true;
}
}
alert("id格式为前两个为小写字母,后面四位数字");
return false;
}
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星