编写datacheck()判断动态生成的文本内值是否为0或空,不然就跳出提示框~~ file3,files是什么对象?程序好像不全! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 file1,2,3是表格单元格,也就是一个表格里动态插入单元格 <script>function datacheck(){ var b; b=(document.all.Text1.value==0)||(document.all.Text1.value=""); if (b==true) { alert("Text1为空或0"); return false;; } b=(document.all.project1.value==0)||(document.all.project1.value="") if (b==true) { alert("project1为空或0"); return false; } return true;}</script><table><tr><td><input name="hours1" align="lift" type="text" value="0" size="2" maxlength="2" ID=Text1></td></tr><tr><td><input name="project1" type="text" id="project1"></td></tr><tr><td><img src="images/search.gif" name="add1" width="24" height="24" border="0" align="absmiddle" onclick="window.open('projectlist.jsp?nfiles=fe1')"></td></tr></table><input type="button" onclick="return datacheck()" value="提交" ID=Submit1> 答clare2003(忘情火):我说的是有好几个文本,ID是 text+变量比如text1,text2,text3,我要一个循环判断这些text里哪个是0或者空,如果有的话就跳出提示。我把你那个加工了一下但是不行,哪位高手帮我耐心点看看哪里错了~~好吗,请耐心点哦,感激不尽?说明:file1,file2,file3是表中单元格,动态生成的text是这样子的input type="text" name="hours'+nfiles+'"<script>var nfiles = 2;function Expand(){nfiles++;if (nfiles>6) {alert("参与工程数不能超过5个");}else {file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时');file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">');file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">');}return false;}function datacheck(){for(int i=2;i<=nfiles;i++) { var b; b=(document.all.hours'+i+'.value==0)||(document.all.hours'+i+'.value="") if (b==true) { alert("Text为空或0"); return false;; } b=(document.all.project'+i+'.value==0)||(document.all.project'+i+'.value="") if (b==true) { alert("project1为空或0"); return false; } return true;}}}</script> <script>var nfiles = 2;function Expand(){ nfiles++; if (nfiles>6) { alert("参与工程数不能超过5个"); }else { file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时'); file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">'); file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">'); } return false;}function datacheck(){// EROROR int: for(var i=2;i<=nfiles;i++) { //ERROR var $1=document.getElementById("hours"+i).value; if ($1=="0"||$1=="") { alert("Text为空或0"); return false; } var $2=document.getElementById("project"+i).value; //ERROR if ($2==""||$2=="0") { alert("project1为空或0"); return false; } return true; }}</script> 我在form 里调用这个JS函数:<form name="form1" method="post" onsubmit="return datacheck();" action="executeroolbook.jsp">为什么还是没有判断是否为空或零就递交了呢?递交到executeroolbook.jsp后数据库也更新了,就是没跳出alert~~? JS读取Xml文件节点属性 求助,实在不知道怎么弄了。 唉,不得不来发问了,给我写段可以用的代码,时间间隔的,两个时间,有分时秒的 关于JS调用VBA后台WINWORD程序关闭问题 扫描二维码串口数据读取至网页中 新手 JavaScript 下拉菜单下拉后,点击窗体任何别的位置,下拉菜单就隐藏了 javascript 如何得到长数字 高分请教有关聊天室里的javascript的代码,在线~~ 在iframe中如何关闭窗口? 奇怪的现象,实在找不出原因,代码就那么几行呀,贴出来大家看看 大家是否同意:通过http播放的媒体,可以试听就肯定可以下载
function datacheck()
{
var b;
b=(document.all.Text1.value==0)||(document.all.Text1.value="");
if (b==true)
{
alert("Text1为空或0");
return false;;
}
b=(document.all.project1.value==0)||(document.all.project1.value="")
if (b==true)
{
alert("project1为空或0");
return false;
}
return true;}
</script>
<table>
<tr>
<td>
<input name="hours1" align="lift" type="text" value="0" size="2" maxlength="2" ID=Text1>
</td>
</tr>
<tr><td>
<input name="project1" type="text" id="project1">
</td></tr>
<tr><td>
<img src="images/search.gif" name="add1" width="24" height="24" border="0" align="absmiddle" onclick="window.open('projectlist.jsp?nfiles=fe1')">
</td></tr>
</table>
<input type="button" onclick="return datacheck()" value="提交" ID=Submit1>
说明:file1,file2,file3是表中单元格,动态生成的text是这样子的input type="text" name="hours'+nfiles+'"
<script>
var nfiles = 2;
function Expand(){
nfiles++;
if (nfiles>6) {
alert("参与工程数不能超过5个");
}else {
file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时');
file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">');
file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">');
}
return false;
}
function datacheck()
{
for(int i=2;i<=nfiles;i++)
{ var b;
b=(document.all.hours'+i+'.value==0)||(document.all.hours'+i+'.value="")
if (b==true)
{
alert("Text为空或0");
return false;;
}
b=(document.all.project'+i+'.value==0)||(document.all.project'+i+'.value="")
if (b==true)
{
alert("project1为空或0");
return false;
}
return true;
}
}
}
</script>
var nfiles = 2;
function Expand(){
nfiles++;
if (nfiles>6) {
alert("参与工程数不能超过5个");
}else {
file1.insertAdjacentHTML('BeforeEnd','<input name="hours'+nfiles+'" id="hours'+nfiles+'" align="lift" type="text" value="0" size="4" maxlength="2">'+'小时');
file2.insertAdjacentHTML('BeforeEnd','<input name="project'+nfiles+'" type="text" id="project'+nfiles+'">');
file3.insertAdjacentHTML('BeforeEnd','<img src="images/search.gif" name="add'+nfiles+'" width="24" height="24" border="0" align="absmiddle" onclick="window.open(\'projectlist.jsp?nfiles='+nfiles+'\')">');
}
return false;
}
function datacheck()
{
// EROROR int:
for(var i=2;i<=nfiles;i++)
{
//ERROR
var $1=document.getElementById("hours"+i).value;
if ($1=="0"||$1=="")
{
alert("Text为空或0");
return false;
}
var $2=document.getElementById("project"+i).value;
//ERROR
if ($2==""||$2=="0")
{
alert("project1为空或0");
return false;
}
return true;
}
}
</script>
<form name="form1" method="post" onsubmit="return datacheck();" action="executeroolbook.jsp">
为什么还是没有判断是否为空或零就递交了呢?递交到executeroolbook.jsp后数据库也更新了,就是没跳出alert~~?