标题:请帮忙看看怎样实现a的循环
取消只看楼主
yessanya
Rank: 2
等 级:论坛游民
帖 子:69
专家分:20
注 册:2007-6-23
结帖率:66.67%
已结贴  问题点数:10 回复次数:2 
请帮忙看看怎样实现a的循环
问题:实现全选或半选
<script>
    function fncSelectAll(obj){
        var (a=1;a.length-1;a++)
        var objs=document.getElementsByName(obj.name+ [a]);
        for(var i=0;i <objs.length;i++){
            objs[i].checked=obj.checked;
        }
    }
</script>

<form method="post" id="form" name="form" action="n.asp">
<input type="checkbox" name="X1">
<input type="checkbox" name="X2">
<input type="checkbox" name="X3">
<input type="checkbox" name="X4">
<input type="checkbox" name="X5">
<input type="checkbox" name="X6">
<input type="checkbox" name="X7">
<input type="checkbox" name="X8">
<input type="checkbox" name="X9">
<input type="checkbox" name="X10">
<input type="checkbox" name="X11">
<input type="checkbox" name="X12">
<input type=checkbox name=X  onclick="fncSelectAll(this)"> 全选
</form>

搜索更多相关主题的帖子: function action method 
2011-11-01 21:11
yessanya
Rank: 2
等 级:论坛游民
帖 子:69
专家分:20
注 册:2007-6-23
得分:0 
以下是引用xmlz在2011-11-2 08:59:34的发言:

function fncSelectAll(obj){  
var objs = document.getElementById("form1").getElementsByTagName("checkbox");
var a=objs.length;
        for(var i=0;i
以上测试不成功,请在看看,谢谢!
<script>
function fncSelectAll(obj){
var objs = document.getElementById("form").getElementsByTagName("checkbox");
var a=objs.length;
        for(var i=0;i <a;i++){
            objs[i].checked=obj.checked;
        }
    }
</script>
<form method="post" id="form" name="form" action="n.asp">
<input type="checkbox" name="X1">
<input type="checkbox" name="X2">
<input type="checkbox" name="X3">
<input type="checkbox" name="X4">
<input type="checkbox" name="X5">
<input type="checkbox" name="X6">
<input type="checkbox" name="X7">
<input type="checkbox" name="X8">
<input type="checkbox" name="X9">
<input type="checkbox" name="X10">
<input type="checkbox" name="X11">
<input type="checkbox" name="X12">
<input type=checkbox name=X  onclick="fncSelectAll()"> 全选
</form>

[ 本帖最后由 yessanya 于 2011-11-2 15:27 编辑 ]
2011-11-02 15:25
yessanya
Rank: 2
等 级:论坛游民
帖 子:69
专家分:20
注 册:2007-6-23
得分:0 
谢谢各位!
4楼将name做成了相同的了!6楼的没问题,但是在form内的所有checkbox都会被选中,不太理想,能不能请各位高手再帮忙想想:
1、既满足于范围内不同name全部选定;2、又可以实现选定前6个或后6个
让各位费心了!
2011-11-04 13:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-354007-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.391267 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved