<body><div style="padding-top:10px;height:28px; background-image:url(images/main_10.gif) ; background-repeat:repeat-x;width: 1165px;margin-left: -15px;margin-top: -16px;font-size: 12px"><img src="images/main_14.gif" style="margin-left: 20px;"/>
您现在所在的位置:管理员 → 课程维护 → <span class="bfont">添加课程</span></div><br><br>
<form action="AdminCM_addCourse.action" method="post">
<center>
<table>
<tr>
<td>课程名</td>
<td><s:textfield name="subject.name" theme="simple" size="25"></s:textfield></td>
</tr>
<tr>
<td><s:reset value="重置" theme="simple"></s:reset></td>
<td><s:submit value="提交" theme="simple"></s:submit></td>
</tr>
</table></center>
</form>
</body>
</html>
你的这个用的sturs2 我不知道能加ID不..然后再上面添加一个
<script type="text/javascript">
function test() {
var s1 = document.getElementById("你的课程名id").value;
if (s1 == "") {
alert("xxx不能为空"); //或者在你的输入框旁边加一个span来显示错误信息也行..
} }
</script>追问
还有个问题,照你的方法验证了,但不管成功还是失败都还是跳转到后台执行了后台代码
然后在
<script type="text/javascript">
$(function(){
$("#name").blur(function(){
var name =$(this).val();
if(name==""){
为空操作
}else{
不为空操作
}
});
});
</script>
function test() {
var s1 = document.getElementById("你的课程名id").value;
if (s1 == "") {
alert("课程不能为空不能为空");
}
return false;
}
</script>