function checkform()
{
for(i=0;i<document.all.length;i++)
{
if (document.all(i).value == "")
alert('表单没有填写完整');
document.all(i)..focus();
return;
}
}
{
for(i=0;i<document.all.length;i++)
{
if (document.all(i).value == "")
alert('表单没有填写完整');
document.all(i)..focus();
return;
}
}
解决方案 »
- 如何使用js,获取所在容器的宽度?
- 怎样将外部数据添加到页面中?
- 求代码:输入购买数量,用JavaScript实时计算价格
- 很奇怪的js问题 高手指教~~~~~~~~~谢谢
- 关于51地图的问题
- 对象如何连接?
- 向各位大虾求助,怎样用javaScript编写OnClick()事件?
- 如何在客户端定位TreeView选中的结点?(类似锚点那种定位,高分,急!!)
- 刚才没说清楚,这次争取说清楚一点
- easyui datagrid怎么翻译数据库中的数值
- 在线等,看看这个字符串的简单功能,能否帮我解决一下。
- 关于window.showModalDialog()打开后返回数组的问题,返回的数组总量是空数组,弄了一天也不知道是为什么,只好请兄弟们帮忙了!!
1、if(document.all(i).value=="")这一句就会出错,因为什么我就不用说了吧
2、一组复选框只要勾上一个就算是填写了那个复选框,而你的写法是要必须勾上所有的框框。
{
if ((document.all(i).type=='text') && (document.all(i).value == "")
alert('表单没有填写完整');
document.all(i)..focus();
return;
xxxxxxxxxxxxxx
1 aaa
2 bbb
3 ccc
4 其他 (文本框)
这时如果选择的是4 其他,则必须填写文本框。
如果选择是1,2,3种的一项则不必。
注: 文本框使用与checkbox或radio相一致name来命名的。具体可看我的网页。
<!--
function mm(form)
{
String.prototype.trim = function()
{
return this.replace(/(^\s+)|(\s+$)/g, "");
}
var meizz = {}; //for checkbox radio
for(var i=0; i<form.elements.length; i++)
{
var e = form.elements[i];
switch(e.tagName)
{
case "TEXTAREA" :
if(!e.disabled && e.value.trim()=="" && e.clientHeight>0)
{
alert("不能为空");
e.focus();
return;
} break;
case "SELECT" :
if(!e.disabled && e.value.trim()=="" && e.clientHeight>0)
{
alert("不能为空");
e.focus();
return;
} break;
case "INPUT" :
if(!e.disabled && e.type!="hidden" && e.clientHeight>0)
{
if("text,password,file".indexOf(e.type)>-1 && e.value.trim()=="")
{
alert("不能为空");
e.focus();
return;
}
else if("checkbox,radio".indexOf(e.type)>-1)
{
if(typeof meizz[e.name]=="undefined")
{
var a = document.getElementsByName(e.name);
for(var k=0; k<a.length; k++)
{
if(a[k].checked)
{
meizz[e.name] = a[k].value;
break;
}
}
if(typeof meizz[e.name]=="undefined")
{
alert("不能为空");
e.focus();
return;
}
}
}
} break;
}
}
}
//-->
</SCRIPT><form name=form1>
<input name=a>
<input name=b type=password>
<textarea name=c></textarea><br>
<input type=checkbox name=d><input type=checkbox name=d>
<input type=checkbox name=d><input type=checkbox name=d>
<br><input type=radio name=e><input type=radio name=e>
</form>
<input type=button value=check onclick="mm(document.form1)">