<table width=100% align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'><form name='feedback' method='post' enctype='multipart/form-data' action='../../enews/index.php'><input name='enews' type='hidden' value='AddFeedback'><tr><td width='16%' height=25 bgcolor='ffffff'>名字</td><td bgcolor='ffffff'><input name='title' type='text' value=''>(*)</td></tr><tr><td width='16%' height=25 bgcolor='ffffff'>联系方式</td><td bgcolor='ffffff'><input name='email' type='text' value=''></td></tr><tr><td width='16%' height=25 bgcolor='ffffff'>信息内容</td><td bgcolor='ffffff'><textarea name='saytext' cols='60' rows='12'></textarea></td></tr><tr><td bgcolor='ffffff'></td><td bgcolor='ffffff'><input type='submit' name='submit' value='提交'></td></tr></form></table>我想用JS控制上面三个内容填为必填,然后提交成功后弹出窗口提示成功,点击关闭窗口。真心求。。
alert("too short");
return false;
}
if ($("input[name='email']").val().length==0) {
alert("too short");
return false;
}
if ($("textarea[name='saytext']").val().length==0) {
alert("too short");
return false;
}
var title=document.getElementById('title').value;
if(!title)
{
alert('please input name first.');
return;
}I think you can write the other two...
<table width=100% align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'>
<form name='feedback' method='post' enctype='multipart/form-data' action='../../enews/index.php' onsubmit='return checkForm();'>
<tr>
<td ></td><input name='enews' type='hidden' value='AddFeedback'><tr><td width='16%' height=25 bgcolor='ffffff'>名字</td>
<td bgcolor='ffffff'><input id='title' name='title' type='text' value=''>(*)</td></tr>
<tr>
<td width='16%' height=25 bgcolor='ffffff'>联系方式</td>
<td bgcolor='ffffff'><input id='email' name='email' type='text' value=''></td>
</tr>
<tr>
<td width='16%' height=25 bgcolor='ffffff'>信息内容</td>
<td bgcolor='ffffff'><textarea id='saytext' name='saytext' cols='60' rows='12'></textarea></td>
</tr>
<tr>
<td bgcolor='ffffff'></td>
<td bgcolor='ffffff'><input type='submit' name='submit' value='提交'></td></tr>
</form>
</table>
<script>
function checkForm(){
var result = true;
if(document.getElementById("title").value ==""){
alert("名字不能为空!");
document.getElementById("title").focus();
result = false;
}
else if(document.getElementById("email").value ==""){
alert("联系方式不能为空!");
document.getElementById("email").focus();
result = false;
}
else if(document.getElementById("saytext").value ==""){
alert("信息内容不能为空!");
document.getElementById("saytext").focus();
result = false;
}
return result;
}
</script>
if(result){}
判断下啊 ~