就是一个删除收藏夹的功能,首先获得了每个选择的checkbox的值,作为一个数组(有可能是只有选择一个的),之后调用删除的controller,等删除成功,想遍历一下数组,找到删除的那个checkbox,将这个checkbox上层的div移除,这样避免页面刷新,不知道表达的是否清楚,求大神解答CheckBoxJavaScript遍历

解决方案 »

  1.   

     <script src='http://code.jquery.com/jquery-1.8.3.js'></script>
    <div><input type="checkbox" /></div>
    <div><input type="checkbox" /></div>
    <div><input type="checkbox" /></div>
    <div><input type="checkbox" /></div>
    <input type="button" value="删除" onclick="del()" />
    <script>
        function del() {
            //ajax请求动态页删除的代码,在回调成功中执行下面列出的语句就行了,这里测试就直接删除了,省略了ajax逻辑代码
            $('input:checked').parent().remove()
        }
    </script>
      

  2.   

    按你需求写了个例子<html>
    <head>
     <script src="http://www.csdn.net/js/jquery-1.4.2.min.js"></script>
    </head>
    <body>
    <div id="chs">
    <li class=".checkbox" > <input type="checkbox" name="" value="1" />1</li>
    <li class=".checkbox"><input type="checkbox" name="" value="2" />2</li>
    <li class=".checkbox"><input type="checkbox" name="" value="3" />3</li>
    </div>
        <script type="text/javascript">
    function delSelect(ids ){
    var chs=$('#chs :checkbox'),
    i=chs.length,ids=','+ids+',';
    while(i--)
    if( ids.indexOf(chs[i].value)!=-1 ) $(chs[i]).parent().remove();
     
    }
    alert('删除1,2');
    delSelect(  [1,2] );
        </script>
    </body>
    </html>
      

  3.   


    斑竹大人天天给我解答问题,真是感动得内流满面啊
    就这一句 $('input:checked').parent().remove(),我怎么就那么久都没想到呢,菜鸟就是菜鸟,唉