Javascript 对输入框中的内容进行 “全选/反选”

<</span>script>
    document.write("<</span>ul>");
    for(var i=0;i<</span>18;i++){
        document.write("<</span>li>");
        document.write('<</span>input type="checkbox" value='+ i +'/>888888888888888');
        document.write("<</span>/li>");    
    }

    document.write("<</span>/ul>");
    document.write('<</span>label for="choose"><</span>input id="choose" type="checkbox" onclick="selectAll(this)">全选/全不选<</span>/label>');
<</span>/script>    

 

代码段2
 <</span>script>
    var chks = document.getElementsByTagName("input");
    function selectAll(obj){
        for(i=0;i<</span>chks.length;i++){
            chks[i].checked = obj.checked;
            // 如果不传递 this 对象,使用事件参数的 srcElement 属性获取数据源也是可以的
            // chks[i].checked = event.srcElement.checked;
        }        
    }
<</span>/script>

 

posted @ 2016-10-03 10:26  wenglabs  阅读(1407)  评论(0编辑  收藏  举报