<div id="demo">
<input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/>
</div>
<button onclick="alert(foo('demo'))">test</button>
<script type="text/javascript">
//<![CDATA[
function foo(o){
var a=document.getElementById(o).getElementsByTagName("INPUT");
var c=e=0;
for (var i=0; i<a.length; i++)
a[i].value==""?++c:++e;
return c!=a.length?e!=a.length?false:true:true;
}
//]]>
</script>
<input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/><input/>
</div>
<button onclick="alert(foo('demo'))">test</button>
<script type="text/javascript">
//<![CDATA[
function foo(o){
var a=document.getElementById(o).getElementsByTagName("INPUT");
var c=e=0;
for (var i=0; i<a.length; i++)
a[i].value==""?++c:++e;
return c!=a.length?e!=a.length?false:true:true;
}
//]]>
</script>
但是里面有些地方看不懂,能不能指教一下
比如:a[i].value==""?++c:++e;
return c!=a.length?e!=a.length?false:true:true;
input为空c++否则e++return c!=a.length?e!=a.length?false:true:true;相当于
if (如果为空的input长度==c的长度)true
else if (有值的长度==e的长度) false
else true