jsp 中的 问题
jsp 中如何拿到 title 、cont 的值并判断是否为空,若空,如何弹出提示框为空
<form name="reply" action="ReplyOK.jsp" method="post" >
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootid" value="<%=rootId %>">
<table Border="1">
<tr>
<td>
<input type="text" name="title" size="80" >
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
搜索更多相关主题的帖子:
jsp
----------------解决方案--------------------------------------------------------
用Javascript可以吗?
----------------解决方案--------------------------------------------------------
我学着用了,也不行啊,不知道为什么,我提交的时候它就没有反应啊
<form name="reply" action="ReplyOK.jsp" method="post" onsubmit="return check()">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootid" value="<%=rootId %>">
<table Border="1">
<tr>
<td>
<input type="text" name="title" size="80" >
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="12" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
<script language="javascript">
<!--
//javascript去掉空格函数
function Ltrim(str) { //去掉字符串左边的空格
var i;
for(i=0; i<str.length; i++) {
if(str.chatAt(i) != " ") break;
}
str = str.substring(i, str.length);
return str;
}
function Rtrim(str) { //去掉字符串右边的空格
var i;
for(i=str.length; i>=0; i--) {
if(str.chatAt(i) != " ") break;
}
str = str.substring(0, i + 1);
return str;
}
function Trim(str) {
return LTrim(RTrim(str));
}
function check() {
if(Trim(document.r.reply.title.value) == "") {
alert("Please input the title!");
document.reply.title.focus();
return false;
}
if(Trim(document.reply.cont.value) == "") {
alert("Please input the title!");
document.reply.cont.focus();
return false;
}
return true;
}
-->
</script>
----------------解决方案--------------------------------------------------------
不用这么复杂
<script language="javascript">
function check() {
if(reply.title.value== "") {
alert("Please input the title!");
reply.title.focus();
return false;
}
if(reply.cont.value == "") {
alert("Please input the title!");
reply.cont.focus();
return false;
}
return true;
}
</script>
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽