码迷,mamicode.com
首页 > Web开发 > 详细

w_all_checked - js -checkbox 多选、全选、submit、request

时间:2016-10-31 21:53:57      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:push   bst   console   ret   hang   ring   全选   method   char   

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<?php
$rand = rand(66,99);
$db = array();
for($w=0;$w<$rand;$w++){
    $id = $w+rand(2,879);
    $www = ‘www‘.rand();
    $tmp = array(‘id‘=>$id,‘www‘=>$www);
    $db[] = $tmp;
}
?>


<table>
    <tr>
        <td></td>
        <td>www</td>
    </tr>
    <?php $id_all = ‘‘;
    foreach ($db as $one) { ?>
        <tr>
            <td><input name="checkbox_batch_all" type="checkbox" value="<?= $one[‘id‘] ?>"
                       id="<?= $one[‘id‘] ?>"
                       onclick="w(<?= $one[‘id‘] ?>)"></td>
            <td><?=$one[‘www‘]?></td>
        </tr>
        <?php $id_all .= $one[‘id‘] . ‘w‘;
    }
    $id_all = substr($id_all, 0, strlen($id_all) - 1);
    echo ‘<script>var id_all ="‘ . $id_all . ‘"</script>‘;
    ?>

</table>
<button id="wdel" onclick="wdel()">删除所选</button>
<button style="display: none;" id="wdel_all" onclick="wdel_all(‘<?= $id_all ?>‘)">全部删除</button>
<button id="wdel_all_checked" onclick="wdel_all_checked()">全选/全不选</button>

</form>

<form id="javascript_form_hidden_batch_delete" action="" method="post">
    <input type="text" name="javascript_input_batch_delete" id="javascript_input_hidden_batch_delete">
</form>
</body>
</html>
<script>
    var warr = new Array();
    var arr_distinct = new Array();
    var wvalue = ‘‘;
    function w(id) {
        console.log(id);
        warr.push(id);
        wf(warr);
        var tmp = new Array();
        tmp = w_arr_copy_value(warr);
        arr_distinct = w_arr_distinct(tmp);
        wtip(arr_distinct, arr_distinct);

        var arr_odd = w_arr_odd(arr_distinct, warr);
        wvalue = arr_odd.join(w);
        wf(wvalue);
        // wtip(‘arr_odd‘, arr_odd);

    }
    function w_arr_distinct(arr) {
        for (var wi = 0; wi < arr.length; wi++) {
            var tmp = arr[wi];
            if (arr.length > 1) {
                for (var wj = wi + 1; wj < arr.length; wj++) {
                    if (arr[wj] == tmp) {
                        arr.splice(wj, 1);
                        --wj;
                    }
                }
            }
        }
        return arr;
    }
    //w_arr_distinct(w);
    //   wf(w);
    function w_arr_odd(arr_distinct, warr) {
        var len_arr_distinct = arr_distinct.length;
        var len_arr = warr.length;
        var arr_odd = new Array();
        for (var wi = 0; wi < len_arr_distinct; wi++) {
            var tmp = 0;
            for (var wj = 0; wj < len_arr; wj++) {
                if (arr_distinct[wi] == warr[wj]) {
                    if (tmp == 0) {
                        tmp = 1;
                    }
                    else if (tmp == 1) {
                        tmp = 0;
                    }
                }
            }
            if (tmp == 1) {
                arr_odd.push(arr_distinct[wi]);
            }
        }
        return arr_odd;
    }


    function w_arr_copy_value(w_source) {
        var len = w_source.length;
        var w_arr = new Array();
        var tmp_value = 0;
        for (var w = 0; w < len; w++) {
            tmp_value = w_source.slice(w, w + 1);
            tmp_value = tmp_value + ‘‘; //toString
            tmp_value = parseInt(tmp_value, 10); //toInt
            //  wf(tmp_value);
            w_arr.unshift(tmp_value);
            // wf(w_arr);
        }
        return w_arr;
    }


    function wdel() {
        console.log(del);
        wf(wvalue);
        var str = ‘‘;
        w_all_checked ? str = id_all : str = wvalue;
        if (before_submit(str)) {
            do_submit(str, javascript_input_hidden_batch_delete, javascript_form_hidden_batch_delete);
        }
    }

    var w_all_checked = false;

    function wdel_all_checked() {
        var w = document.getElementsByName(checkbox_batch_all);
        w_all_checked = !w_all_checked;
        for (var wi = 0, len = w.length; wi < len; wi++) {
            w[wi].checked = w_all_checked;
        }
    }

    function before_submit(str) {
        //alert(str.length==0);
        if (str.length == 0) {
            alert(请勾选删除项!);
            return false;
        }
        return true;
    }

    function do_submit(str, input_id, form_id) {
        var w = show_confirm(您确定要删除吗?);
        if (w) {
            change_input_value(input_id, str);
            document.getElementById(form_id).submit();
        }

    }

    function show_confirm(str_tip) {
        var r = confirm(str_tip);
        if (r == true) {
            //alert(‘pressed ok‘);
            return true;
        } else {
            return false;
        }
    }

    function wf(w) {
        console.log(w);
    }
    function wtip(tip, w) {
        console.log(tip);
        console.log(w);
    }

    function change_input_value(input_id, value) {
        wf(value);
        wf(input_id);
        document.getElementById(input_id).value = value;
    }

    function w_true_false(w) {
        w ? w = false : w = true;
        return w;
    }



</script>

 

w_all_checked - js -checkbox 多选、全选、submit、request

标签:push   bst   console   ret   hang   ring   全选   method   char   

原文地址:http://www.cnblogs.com/yuanjiangw/p/6017205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!