为什么我在前端页面将昵称值输入为空时 span标签不提示“用户昵称不能为空!”,而且保存按钮也没禁用啊!!
$("#msg").html("用户昵称不能为空!")
$("#btn").prop("disabled",true)
求指点en
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<img src="user?actionName=userHead&imageName=${user.head}" width="200" height="280"/>
div>
<div class="col-md-8">
<form action="user?action=save" method="post" enctype="multipart/form-data" >
<table width="100%">
<tr>
<td width="20%">更改头像:td>
<td><input type="file" id="imagePath" name="imagePath"/>td>
tr>
<tr>
<td>我的昵称:td>
<td><input type="text" id="nickName" name="nickName" value="${user.nick}"
style="margin-top:5px;height:30px;"/>td>
tr>
<tr>
<td valign="top">我的心情:td>
<td>
<textarea id="mood" name="mood" rows="10" style="width: 100%">${user.mood}
textarea>
td>
tr>
<tr>
<td><button class="btn btn-primary" type="submit" id="btn">保存button>td>
<td>
<button class="btn btn-primary" type="button" onclick="javascript:history.back()">返回button>
td>
<span id="msg" style="color:red" >span>
tr>
table>
form>
div>
div>
div>
div>
body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
$("#nickName").blur(function(){
//获取昵称文本框的值
var nickName= $("#nickName").val();
//判断值是否为空
if(isEmpty(nickName)){
$("#msg").html("用户昵称不能为空!")
$("#btn").prop("disabled",true)
return;
}
//不为空,判断昵称是否做了修改
var nick='${user.nick}';
//没有修改
if(nickName==nick){
return;
}
//昵称做了修改
//发送Ajax请求后台,验证昵称是否可用
$.ajax({
type:"get",
url:"user",
data:{
actionName:"checkNick",
nick:nickName
},
success:function (result){
//如果可用,清空提示信息,按钮可用
if(result.code == 1){
$("#msg").html("")
$("#btn").prop("disabled",false);
}else {//如果不可用
$("#msg").html("该昵称已经存在,请重新输入!")
$("#btn").prop("disabled",true);
}
}
})
}).focus(function (){
$("#msg").html("")
$("#btn").prop("disabled",false);
});
script>
html>
有报错么
代码 标签缺少闭口