求救!!一段javascript代码出现问题,谁能帮帮我!!!!

lindsay 2002-04-25 04:15:42
为什么我在调试的时候总是出现缺少标示符的的提示,谁能帮帮我???



<script language="javascript">
function checkform(form1)
{
if(form1.title.value.length==0)
{
form1.title.focus();
form1.title.select();
alert("您的新闻没有标题吗?");
return false;
}

if(form1.head.value==null)
{
form1.head.focus();
form1.head.select();
alert("请选择新闻类型!");
return false;
}

if((form1.year.value==null)&&(form1.month.value==null)&&(form1.day.value==null))
{
form1.year.focus();
form1.year.select();
form1.month.focus();
form1.month.select();
form1.day.focus();
form1.day.select();
alert("请填写新闻发布日期!");
return false;
}

if((form1.class.value==3) && (form1.pic.value.length==0))
{
form1.pic.focus();
form1.pic.select();
alert("您输入的是图片新闻,请选择合适的图片!");
return false;
}

if(form1.newtext.value.length==0)
{
form1.newtext.focus();
form1.newstext.select();
alert("新闻内容必须填写!");
return false;
}
}

</script>
...全文
30 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
seabell 2002-04-25
  • 打赏
  • 举报
回复
看看这段应该清楚了吧
<script>
function mycheck()
{
alert("text="+form1.myyear.options[form1.myyear.selectedIndex].text);
alert("value="+form1.myyear.options[form1.myyear.selectedIndex].value);
if(form1.myyear.selectedIndex==0)
{
form1.myyear.focus();
//form1.myyear.select();//对于select元素,不可以用select方法(也没必要啊,不是text嘛),清楚了吗
alert("请选择新闻发布年!");
return false;
}
}
</script>
<form name=form1>
<select name=myyear>
<option value=year>年</option>
<option value=2000>2000</option>
<option value=2001>2001</option>
<option value=2002>2002</option>
<option value=2003>2003</option>
</select>
<input type=button value=check onclick=mycheck()>
</form>
lindsay 2002-04-25
  • 打赏
  • 举报
回复
挑时候他说对象不支持此属性或方法!!
有没有更合适的呀???
我都要疯了!!大虾救命!!!
qiushuiwuhen 2002-04-25
  • 打赏
  • 举报
回复
head,year,month,day是下拉列表框

if(form1.head.selectedIndex==0)

if(form1.year.selectedIndex==0)

if(form1.month.selectedIndex==0)

if(form1.day.selectedIndex==0)



lindsay 2002-04-25
  • 打赏
  • 举报
回复
想问一下,在javascript中下拉列表框的内容属性是什么???
lindsay 2002-04-25
  • 打赏
  • 举报
回复
现在这段代码已经改成以下代码:

<script language="javascript">
function checkform(form1)
{
if(form1.mytitle.value.length==0)
{
form1.mytitle.focus();
form1.mytitle.select();
alert("您的新闻没有标题吗?");
return false;
}

if(form1.myhead.value=="")
{
form1.myhead.focus();
form1.myhead.select();
alert("请选择新闻类型!");
return false;
}

if((form1.myyear.value==""))
{
form1.myyear.focus();
form1.myyear.select();
alert("请填写新闻发布日期!");
return false;
}
if(form1.mymonth.value=="")
{
form1.mymonth.focus();
form1.mymonth.select();
alert("请填写新闻发布日期!");
return false;
}
if(form1.myday.value=="")
{
form1.myday.focus();
form1.myday.select();
alert("请填写新闻发布日期!");
return false;
}

if((form1.myclass.value=="3") && (form1.mypic.value.length==0))
{
form1.mypic.focus();
form1.mypic.select();
alert("您输入的是图片新闻,请选择合适的图片!");
return false;
}

if(form1.mytext.value.length==0)
{
form1.mytext.focus();
form1.mytext.select();
alert("新闻内容必须填写!");
return false;
}
}

</script>
孟子E章 2002-04-25
  • 打赏
  • 举报
回复
==null改为==""
seabell 2002-04-25
  • 打赏
  • 举报
回复
lindsay:告诉你一个比较简便又保险的办法,命名时加上前缀my
对于这段代码,你可以来个查找替换,如将class、title都换成myclass、mytitle等等
lindsay 2002-04-25
  • 打赏
  • 举报
回复
谁能告诉我,我这段代码李德标示符都有哪些??
weidegong 2002-04-25
  • 打赏
  • 举报
回复
sorry,很多无用代码也放进去了:(
lindsay 2002-04-25
  • 打赏
  • 举报
回复
title,newtext是文本框
head,year,month,day是下拉列表框
  • 打赏
  • 举报
回复
form1.newtext.focus();
form1.newstext.select();
是newstext还是newtext?
  • 打赏
  • 举报
回复
title,newtext,head,year是些什么?都是textbox吗?还是别的什么?

weidegong 2002-04-25
  • 打赏
  • 举报
回复
呵呵,看看我写的吧,自认为比较经典

用Jsp动态生成











<html>
<head>
<title>
添加新记录
</title>
<LINK href="comDB/article.css" rel=stylesheet type=text/css>

<script language="JavaScript">
<!--
var bCheck=false;//当前是否处于验证状态
var bChecked=false;//输入框是否处于焦点状态
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

String.prototype.Trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.getLength = function(){
var l=this.length;
var n=l
for (var i=0;i<l;i++){
if (this.charCodeAt(i)<0||this.charCodeAt(i)>255) n++
}
return n
}

function check(){
if(bChecked==true) return false;
bCheck=true;
var inputs=document.frmAdd.all.tags("INPUT");

for(var i=0;i<inputs.length;i++){
//去掉所填项目左右空格
var tmp=inputs[i].value;
inputs[i].value=tmp.Trim();

//如果必填项未填,要求填写
if(inputs[i].value.length<=0 && inputs[i].style.isnullable==0){
alert("请填写 ["+ inputs[i].style.name + "] 的相关信息。\n注:带有'*'号的项目为必填项目,请全部填写。");
inputs[i].focus();
bCheck=false;
return false;
}

//如果超过允许的最大长度,要求重新填写
/*
if(inputs[i].value.getLength()>inputs[i].style.maxlength && inputs[i].style.maxlength>0){
alert("'" + inputs[i].style.name + "' 允许输入的最大字符数是:" + inputs[i].style.maxlength +"\n 请您重新输入。");
inputs[i].focus();
return false;
}
*/
}//end for(var i=0;i<inputs.length;i++)

bCheck=false;
return true;
}

function testCheck(obj){
if(bCheck==true) obj.select();
bCheck=false;
bChecked=true;
}
//-->
</script>

</head>
<body>
<form name=frmAdd method="POST" onsubmit="return check()" action="UploadAdd.jsp" >
<div align="center">
<table border="1" cellspacing="0" width="60%"
bgcolor="#F0F8FF" bordercolorlight="#11B1FF" bordercolordark="#F0F8FF">
<tr>
<td width="100%" bgcolor="#0080C0" height="20">
<div align="center">
<p><b><font
color="#FFFFFF">添加新记录</font></b>
</div>
</td>
</tr>
<tr align="center">
<td width="100%">
<table bgColor=#f0f8ff border=1 borderColorDark=#ecf5ff borderColorLight=#4da6ff cellSpacing=0 width="100%">



<tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
权限编码<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">

<!-- 在此添加其他输入框的代码 !-->

<input type="Text" value=
"" name="Code" size="70" class="smallinput" style="width:100%;isnullable:0;name:权限编码;maxlength:2"
onblur='bChecked=false;if(this.value.getLength()>2) {alert("[权限编码] 的最大长度是2,请重新填写。");bCheck=true;this.focus();return false;}'

onfocus=testCheck(this)>




<tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
权限级别<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">

<!-- 在此添加其他输入框的代码 !-->

<input type="Text" value=
"" name="Class" size="70" class="smallinput" style="width:100%;isnullable:0;name:权限级别;maxlength:1"
onblur='bChecked=false;if(this.value.getLength()>1) {alert("[权限级别] 的最大长度是1,请重新填写。");bCheck=true;this.focus();return false;}'

onfocus=testCheck(this)>




<tr>
<td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
说明<font color=#FF0000 > *</font></font></b></td>
<td width="62%" height="30">

<!-- 在此添加其他输入框的代码 !-->

<input type="Text" value=
"" name="Remark" size="70" class="smallinput" style="width:100%;isnullable:0;name:说明;maxlength:50"
onblur='bChecked=false;if(this.value.getLength()>50) {alert("[说明] 的最大长度是50,请重新填写。");bCheck=true;this.focus();return false;}'

onfocus=testCheck(this)>


<input name="paramTableName" type =hidden value="popedom">
<input name="paramSubmitAdd" type=hidden value="True">
<input name="paramAfterAdd" type=hidden value="http://localhost:8080/PDMShow.jsp">
<input name="paramSQLWhere" type =hidden value="">



</table>
</td>
</tr>
</table>
</div>
<div align="center">
<p>
<input type="submit" value=" 确 定 " name="cmdok" class="buttonface" >
 
<input type="reset" value=" 复 原 " name="cmdcancel" class="buttonface">
 
<input type="button" value=" 返 回 " name="cmdreturn" class="buttonface" onclick="MM_goToURL('self','http://localhost:8080/PDMShow.jsp');return document.MM_returnValue">
</p>
</div>
</form>
</body>
</html>
lindsay 2002-04-25
  • 打赏
  • 举报
回复
还有没有别的呀
它提示是在year,month,day那一块,我也搞不懂了??
孟子E章 2002-04-25
  • 打赏
  • 举报
回复
提示哪行错误?不要用js的关键子
孟子E章 2002-04-25
  • 打赏
  • 举报
回复
提示哪行错误?不要用js的关键子
孟子E章 2002-04-25
  • 打赏
  • 举报
回复
form1.class.value
不要用class做名字

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧