请教大家 ,这样客户端校验的JAVASCRIPT代码怎么写?进来看看,多谢大家! if(document.formq.test[i].value=="")应该是把formq改成form1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你还漏了一个},你用了for和if,但是只有一个} 上面各位:你们误会了我的意思,我的意思是我通过这样的方式来判断。语法错误我也知道,但是不能够判断在一个Form里面,我用表格定位来动态生成 一系列的 <input>,可能是一个,也可能是多个。怎么用JAVASCRIPT来判断它必须为什么输入项,也是判断它的值不能为空。 for(var i=0;i<document.form1.test.length;i++){ if(document.form1.test[i].value==""){ alert("Please select the category!"); return false; break; } } <form action=about:ok><input type=button value=addInput onclick=addInput()><input type=submit value=submit onclick=return(check())><table border id=t></table></form><script>function addInput(){t.insertRow().insertCell().innerHTML="<input name=test>"}function check(){var o=document.getElementsByName("test")for(var i=0;i<o.length;i++){ if(o[i].value==""){ alert("Please select the category!"); o[i].select(); return false; } }}</script> “document.form1.test[i]”是什么东西啊?如果有多个控件同名,用 document.form1.elements("name") 得到这些控件的集合// checkInput 为通用的检查函数function checkInput(sFormName, sControlName){ var oColl = document.forms(sFormName).elements(sControlName); for(var i=0;i<oColl.length;i++){ if(doColl[i].value==""){ alert("Please select the category!"); return false; } } return true;}// 检查 form1.testif ( checkInput("form1", "test") ) //okelse //bad if(doColl[i].value==""){==>if(oColl[i].value==""){ alexxing(赤铸): 我按照你的代码写一个小程序来测试,但是提交的时候,总是会提交上去。而不能当返回FALSE的时候就不提交,你帮忙看看如何,多谢了先:代码如下: <HTML><HEAD><TITLE>test</TITLE><SCRIPT LANGUAGE="JavaScript"><!-- function checkInput(sFormName, sControlName) { var oColl = document.forms(sFormName).elements(sControlName); for(var i=0;i<oColl.length;i++){ if(oColl[i].value==""){ alert("Please select the category!"); return false; } } return true; } // 检查 form1.test function check(){ if (checkInput("form1", "a")){ return false; } if (checkInput("form1", "b")){ return false; } document.form1.submit(); }//--></SCRIPT></HEAD><BODY bgcolor="#FFFFFF"><form name="form1" method="post" action="" > <table width="100%" border="1" cellspacing="0" cellpadding="1"> <tr> <td width="31%"> <input type="text" name="a"> </td> <td width="69%"> <select name="b"> <option>test</option> <option value="d">dd</option> <option value="d">s</option> </select> </td> </tr> <tr> <td width="31%"> <input type="text" name="a"> </td> <td width="69%"> <select name="b"> <option>test</option> <option value="d">d</option> <option value="dd">ss</option> </select> </td> </tr> <tr> <td width="31%"> </td> <td width="69%"> </td> </tr> <tr> <td width="31%"> </td> <td width="69%"> <input type="button" name="Submit" value="Submit" onclick="return check();"> <input type="button" name="Submit2" value="Button"> </td> </tr> </table></form></BODY></HTML> jquery中为什么这个的结果会不同? Css可否改变滚动条的样式? 关于正则的问题~~在线等解答~~ 急求javascript 对象不支持此属性或方法.找了半天也不知道哪里错了 ext3.0框架问题 不懂这个滚动图片代码的原理,表面意思知道,解释一下,谢谢。。。 求把json字符串转换为json对象的方法 js 触发键盘事件 如何让图片的alt或链接的title变得半透明。 js实现下载快捷方式-将站点的快捷打开方式放到桌面 如何判断文本框里的内容是否为空? 如何实现代码不执行,只出现原代码,该换行的换行,
你们误会了我的意思,我的意思是我通过这样的方式来判断。
语法错误我也知道,但是不能够判断
在一个Form里面,我用表格定位来动态生成 一系列的 <input>,
可能是一个,也可能是多个。
怎么用JAVASCRIPT来判断它必须为什么输入项,也是判断它的值不能为空。
for(var i=0;i<document.form1.test.length;i++){
if(document.form1.test[i].value==""){
alert("Please select the category!");
return false;
break;
}
}
<input type=button value=addInput onclick=addInput()>
<input type=submit value=submit onclick=return(check())>
<table border id=t></table>
</form>
<script>
function addInput(){
t.insertRow().insertCell().innerHTML="<input name=test>"
}
function check(){
var o=document.getElementsByName("test")
for(var i=0;i<o.length;i++){
if(o[i].value==""){
alert("Please select the category!");
o[i].select();
return false;
}
}
}
</script>
如果有多个控件同名,用 document.form1.elements("name") 得到这些控件的集合// checkInput 为通用的检查函数
function checkInput(sFormName, sControlName)
{
var oColl = document.forms(sFormName).elements(sControlName);
for(var i=0;i<oColl.length;i++){
if(doColl[i].value==""){
alert("Please select the category!");
return false;
}
}
return true;
}// 检查 form1.test
if ( checkInput("form1", "test") )
//ok
else
//bad
我按照你的代码写一个小程序来测试,但是提交的时候,总是会提交上去。而不能当返回FALSE的时候就不提交,你帮忙看看如何,多谢了先:
代码如下:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkInput(sFormName, sControlName)
{
var oColl = document.forms(sFormName).elements(sControlName);
for(var i=0;i<oColl.length;i++){
if(oColl[i].value==""){
alert("Please select the category!");
return false;
}
}
return true;
}
// 检查 form1.test
function check(){
if (checkInput("form1", "a")){
return false;
}
if (checkInput("form1", "b")){
return false;
}
document.form1.submit();
}
//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="#FFFFFF">
<form name="form1" method="post" action="" >
<table width="100%" border="1" cellspacing="0" cellpadding="1">
<tr>
<td width="31%">
<input type="text" name="a">
</td>
<td width="69%">
<select name="b">
<option>test</option>
<option value="d">dd</option>
<option value="d">s</option>
</select>
</td>
</tr>
<tr>
<td width="31%">
<input type="text" name="a">
</td>
<td width="69%">
<select name="b">
<option>test</option>
<option value="d">d</option>
<option value="dd">ss</option>
</select>
</td>
</tr>
<tr>
<td width="31%"> </td>
<td width="69%"> </td>
</tr>
<tr>
<td width="31%"> </td>
<td width="69%">
<input type="button" name="Submit" value="Submit" onclick="return check();">
<input type="button" name="Submit2" value="Button">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>