先谢谢大家
想实现如下效果
<input type="button" onclick="test(0)">
<input type="checkbox" value="1">
<input type="checkbox" value="2">
.... 有很多checkbox .....
当checkbox被选中时<input type="button" onclick="test(0)">的参数要有变化,如下:
一个被勾选时<input type="button" onclick="test(1)">
两个被勾选时<input type="button" onclick="test(1,2)">
多个被勾选时<input type="button" onclick="test(1,2,3,....)">
想实现如下效果
<input type="button" onclick="test(0)">
<input type="checkbox" value="1">
<input type="checkbox" value="2">
.... 有很多checkbox .....
当checkbox被选中时<input type="button" onclick="test(0)">的参数要有变化,如下:
一个被勾选时<input type="button" onclick="test(1)">
两个被勾选时<input type="button" onclick="test(1,2)">
多个被勾选时<input type="button" onclick="test(1,2,3,....)">
在执行test之前检查有几个checkbox是选中的不就好了
var params = "";
function test()
{
var ssssss;
if(params != "")
{
ssssss = params.substring(0,params.length-1);;
}
ssssss = "0";
..........
}
function cbChecked(obj)
{
var value = obj.value;
if(obj.checked)
{
var tmp = ","+params + ",";
if(tmp.indexOf(","+value+",") < 0)
params += value + ",";
}
else
{
params = params.replace(value+",","");
}
}
<input type="checkbox" onclick="cbChecked(this);" value="2" />
<input type="checkbox" onclick="cbChecked(this);" value="3" />
<input type="checkbox" onclick="cbChecked(this);" value="4" />
<input type="checkbox" onclick="cbChecked(this);" value="5" />
<input type="checkbox" onclick="cbChecked(this);" value="6" />
<input type="checkbox" onclick="cbChecked(this);" value="7" /><input type="button" onclick="test()">
var array = document.getElementsByName("test");
var j = 0;
for(var i=0;i<array.length;i++){
if(array[i].checked)
j++;
}
alert(j);
</script>
<input type="button" value="button" onclick="test()"
<input type="checkbox" name = "test" value="2" />
<input type="checkbox" name = "test" value="3" />
<input type="checkbox" name = "test" value="4" />
<input type="checkbox" name = "test" value="5" />
<input type="checkbox" name = "test" value="6" />
<input type="checkbox" name = "test" value="7" />
<input type="checkbox" value="1" onclick='check(this);'>
<input type="checkbox" value="2" onclick='check(this);'>
...
<script>
var checkValues=',';
var check=function(o)
{
var f=(checkValues.indexOf(','+o.value+',')==-1);
if(o.checked) { if(f) checkValues+=o.value+','; }
else if(!f) checkValues=checkValues.replace(','+o.value+',',',');
};
var callTest=function() { eval('test('+(checkValues.length==1?'0':checkValues.substring(1,checkValues.length-1))+');'); };
</script>
echo "don't know";