A multiple button events

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

There are times when we simply just to modify the operation of state data, more buttons can modify multiple events, in order to increase the reusability of code, we can also use a button to modify an event, or an event multiple buttons ( It allows users to compare aware of their actions);

The following is about a method more buttons:

HTML code:

@*首先我们设置按钮的时候,给它的点击事件带一个参数*@
<button type="button" onclick="BlankOut(0)">作废</button>
<button type="button" onclick="BlankOut(1)">取消作废</button>

<script type="text/javascript">
//作废||取消作废 点击按钮事件
    function BlankOut(If) {
        var IfState;
//通过判断传过来的参数,初始化状态值
        if (If == 0) {
            IfState = true;
        }
        else {
            IfState = false;
        }
        var check = $("#HuZhuGuanLi :checkbox:checked");//获取选中的CheckBox, 
        var array = new Array();//申明一个数组
        //判断是否有选中数据
        if (check.length > 0) {
            //如果有,便通过循环遍历将选中CheckBox的值插入数组。
            for (var i = 0; i < check.length; i++) {
                array.push(check[i].value);
            }
            $.post("AmendStateT?array=" + array + "&IfState=" + IfState, function(data) {
                if (data.State) {
                    layer.msg(data.Text, { offset: "150px", anim: 1 });
                    HuZhuGuanLi.refreshPage();//刷新表格
                }
                else {
                    layer.msg(data.Text, { offset: "150px", anim: 1 });
                }
            });
        }
    }
</script>

Controller Code:  

A writing method, parameter receiving attention, IfState output value of true or false;

By pass over the value of the judgment set aside or cancel interface action is void,

Pass over in front of an array, and the data in the form of the above chart, we need to split it

 

Then loop through, to determine whether we need to do the same action with the data, the same thing will not do the operation.

This way we can improve the reusability of code.

Guess you like

Origin blog.csdn.net/qq_44551864/article/details/94958645