<br>姓名: <input type="text" name="aaaa" size="12"> 你的name怎么都取关键字呀,换一下leaMsgBoard.name.value 这样的都换成下面的
document.getElementsByName("laaaa")[0].value
document.getElementsByName("laaaa")[0].value
解决方案 »
- 浮动div被flash给挡住了
- Myeclipse导入项目的时候报错Background Indexer Crash Recovery java.lang.StackOverflowError
- 请教javascript高手个问题
- 一个JS传递动态变量的问题,求高手解答!
- 我觉得不通顺啊 先发后等吧
- 求一验证类路径com.ibm.eclipse的正则表达式
- 改变窗口?
- 发布,讨论,dhCombobox,可输入,选择,自动匹配
- 用window.open打开的窗口的一个小问题?
- 数据输入问题~!各位看看
- 求助。怎么用JS验证,本文框中输入的日期或数字,鼠标放进去时,日期的横线,数字的逗号分隔符就消失了,鼠标离开又出现了
- 要两个事件同时发生,怎么做?
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background="../src/back.gif";
}
</style> //这里不要写在<script></script>里function formCheck()
{
if(leaMsgBoard.name.value==""){
alert("请输入你的姓名!");
leaMsgBoard.name.focus();
return false;
}
if(leaMsgBoard.class.value==""){ //class是保留字.
alert("请输入你的班级!");
leaMsgBoard.class.focus();
return false;
} if(leaMsgBoard.contact.value==""){
alert("请填入你的电子邮件!");
leaMsgBoard.contact.focus();
return false;
}
}
</script> <form action="setMsg.jsp" method="post" name="leaMsgBoard" onsubmit="return formCheck()" >
<table width="700" border="0" align="center" cellpadding="4" 1" bgcolor="#ebcellspacing="ebeb">
<tr>
<td>
<br>姓名: <input type="text" name="name" size="12">
<p>班级: <input type="text" name="class" size="12"> </p>
<P>联系方式: <input type="text" name="contact" size="20"> </p>
<input type="submit" name="SubmitBtn" value="确认">
</td> </tr> </table>
</form>
html:
<form action="setMsg.jsp" method="post" name="leaMsgBoard" onsubmit="return formCheck()" >
<table width="700" border="0" align="center" cellpadding="4" 1" bgcolor="#ebcellspacing="ebeb">
<tr>
<td>
<br>姓名: <input type="text" name="mc" size="12">
<p>班级: <input type="text" name="bj" size="12"> </p>
<P>联系方式: <input type="text" name="lxfs" size="20"> </p>
<input type="submit" name="SubmitBtn" value="确认">
</td> </tr> </table>
</form>
js:
function formCheck()
{
if(leaMsgBoard.mc.value==""){
alert("请输入你的姓名!");
leaMsgBoard.mc.focus();
return false;
}
if(leaMsgBoard.bj.value==""){
alert("请输入你的班级!");
leaMsgBoard.bj.focus();
return false;
} if(leaMsgBoard.lxfs.value==""){
alert("请填入你的电子邮件!");
leaMsgBoard.lxfs.focus();
return false;
}
}
改后的全部代码:
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="msgStyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background="../src/back.gif";
}
</style>
<script language="JavaScript">
function formCheck()
{
if(leaMsgBoard.names.value==""){
alert("请输入你的姓名!");
leaMsgBoard.name.focus();
return false;
}
if(leaMsgBoard.classes.value==""){
alert("请输入你的班级!");
leaMsgBoard.classes.focus();
return false;
}
if(leaMsgBoard.content.value==""){
alert("留言不能为空!");
leaMsgBoard.content.focus();
return false;
}
if(leaMsgBoard.contact.value==""){
alert("请填入你的电子邮件!");
leaMsgBoard.contact.focus();
return false;
}
if (leaMsgBoard.GetCode.value=="")
{
alert("请填写验证码。");
leaMsgBoard.GetCode.focus();
return false;
}
return true;
}
//......省略部分
</script>
</head><body>
<%-- Begin of the form --%>
<form action="setMsg.jsp" method="post" name="leaMsgBoard" onSubmit="return formCheck()">
<table width="700" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#ebebeb">
<tr>
<td class="pt9">
<br> 姓名: <input type="text" name="names" size="12" />
<p> 班级: <input type="text" name="classes" size="12" /></p>
<P> 联系方式: <input type="text" name="contact" size="20" /></p><table width="100%" border="0" cellpadding="0" cellspacing="0" class="pt9">
<tr>
<td width="50" valign="top">留言:</td>
<td>
<table width="98%">
<tr><td><textarea name="Message" id="content" rows=10 cols=98%></textarea> </td></tr>
</table>
</td>
</tr>
</table><table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="62%">*请输入右侧的验证码:
<input name="GetCode" type="text" id="GetCode" size="4" maxlength="4" /> <img src="../src/editor/GetCode.bmp" width="72" height="18" id="GetCodeImg" /></td>
<td width="38%">
<input name="replyer" type="hidden" value="" />
<input name="reply_content_id" type="hidden" value="" />
<input name="userid" type="hidden" value="48327" />
<input type="hidden" name="sum_upload_file_size" value="0" />
<input type="hidden" name="upload_files" value="" />
<input type="hidden" name="upload_file_count" value="0" />
<input type="submit" name="SubmitBtn" id="SubmitBtn" value="确认留言" />
<input type="reset" name="Reset" value="取 消"/>
</td>
</tr>
</table>
</td>
</tr></table>
</form>
<!-- End of the Form -->
<!-- begin of the list of Messages -->
//......省略部分
<!-- End of the list of Messages --> <!-- End --> </body>
</html>
function formCheck()
{
if(leaMsgBoard.names.value==""){
alert("请输入你的姓名!");
leaMsgBoard.name.focus();
return false;
}
//......其它不变
leaMsgBoard.submit();
</script>
把<form action="setMsg.jsp" method="post" name="leaMsgBoard" onSubmit="return formCheck()">
中的onSubmit="return formCheck()"去掉,改为
<form action="setMsg.jsp" method="post" name="leaMsgBoard">
放在JS里面提交;
alert("请输入你的姓名!");
leaMsgBoard.name.focus();
return false;
}
这里出错了,变量名没改彻底.应改为: leaMsgBoard.names.focus();
在JS中任何一个小错误都会导致后面的JS代码不被执行(在不调试状态下又没有提示).
2、你写的leaMsgBoard.name.value好像取不到,老老实实用id取把
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background="../src/back.gif";
}
</style>
<script language="JavaScript">
function formCheck()
{
alert()
if(leaMsgBoard.oname.value==""){
alert("请输入你的姓名!");
leaMsgBoard.oname.focus();
return false;
}
if(leaMsgBoard.oclass.value==""){
alert("请输入你的班级!");
leaMsgBoard.oclass.focus();
return false;
} if(leaMsgBoard.contact.value==""){
alert("请填入你的电子邮件!");
leaMsgBoard.contact.focus();
return false;
}
}
</script> <form action="setMsg.jsp" method="post" name="leaMsgBoard" onsubmit="return formCheck();" >
<table width="700" border="0" align="center" cellpadding="4" 1" bgcolor="#ebcellspacing="ebeb">
<tr>
<td>
<br>姓名: <input type="text" name="oname" size="12">
<p>班级: <input type="text" name="oclass" size="12"> </p>
<P>联系方式: <input type="text" name="contact" size="20"> </p>
<input type="submit" name="SubmitBtn" value="确认">
</td> </tr> </table>
</form>很简单的问题 把你的<style>拿到<script>标签外面即可 还有别以关键字命名
{document.images.faceimg.src=face_image[parseInt(document.leaMsgBoard.face.options[document.leaMsgBoard.face.selectedIndex].value)];
}
face_image=new Array(16);
face_image[0]=../src/headpics/m01.gif";
face_image[1]=../src/headpics/m02.gif";
face_image[2]=../src/headpics/m03.gif";
face_image[3]=../src/headpics/m04.gif";
face_image[4]=../src/headpics/m05.gif";
face_image[5]=../src/headpics/m06.gif";
face_image[6]=../src/headpics/m07.gif";
face_image[7]=../src/headpics/m08.gif";
face_image[8]=../src/headpics/m09.gif";
face_image[9]=../src/headpics/m10.gif";
face_image[10]=../src/headpics/m11.gif";
face_image[11]=../src/headpics/m12.gif";
face_image[12]=../src/headpics/m13.gif";
face_image[13]=../src/headpics/m14.gif";
face_image[14]=../src/headpics/m15.gif";
face_image[15]=../src/headpics/m16.gif";在form表单中与之对应的是:
<td width="120" rowspan="3" align="center" valign="top"><br>
选择头像<br>
<br>
<SELECT size=1 name="face" onchange=showimage()>
<option value="0" selected>好开心</option>
<option value="1">好难过</option>
<option value="2">好伤心</option>
<option value="3">要唱歌</option>
<option value="4">正哭泣</option>
<option value="5">很满意</option>
<option value="6">很惊喜</option>
<option value="7">好生气</option>
<option value="8">好害怕</option>
<option value="9">真倒霉</option>
<option value="10">扁着嘴</option>
<option value="11">平常心</option>
<option value="12">冒冷汗</option>
<option value="13">伤脑筋</option>
<option value="14">笑死了</option>
<option value="15">好气愤</option>
</SELECT>
<br>
<br>
<br>
<img src="../src/headpics/m01.gif" name="faceimg" id="faceimg" /></td>请问该怎样改啊??
face_image[0]=../src/headpics/m01.gif";
face_image[1]=../src/headpics/m02.gif";
face_image[2]=../src/headpics/m03.gif";
face_image[3]=../src/headpics/m04.gif";
face_image[4]=../src/headpics/m05.gif";
face_image[5]=../src/headpics/m06.gif";
face_image[6]=../src/headpics/m07.gif";
face_image[7]=../src/headpics/m08.gif";
face_image[8]=../src/headpics/m09.gif";
face_image[9]=../src/headpics/m10.gif";
face_image[10]=../src/headpics/m11.gif";
face_image[11]=../src/headpics/m12.gif";
face_image[12]=../src/headpics/m13.gif";
face_image[13]=../src/headpics/m14.gif";
face_image[14]=../src/headpics/m15.gif";
face_image[15]=../src/headpics/m16.gif"; 看到双引号没有匹配到了吗?