The python JQuery (batch operations, monitor button)

Listening window keyboard events: 
    (snoop shift Press) (keyDown, the keyCode)
     // define global variables, whether monitor keyboard shift is pressed, a code corresponding shift is 16 
    var In Flag = to false;
     // note window object , e is the event itself 
    $ (window) .on ( " keyDown " , function (E) {
         IF (e.keyCode === 16 ) { 
            falg = to true; 
        } 
    }); 
    
    
# - shift-batch operation example 
    <! DOCTYPE HTML> 
    <HTML lang = " EN " > 
    <head> 
        <Meta charset = " UTF-. 8 " > 
        <title> the title </title> 
    </ head>
    <body>
    <table border="1px">
        <thead>
        <tr>
            <th>选择</th>
            <th>姓名</th>
            <th>功能</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><input type="checkbox"></td>
            <td>林同学</td>
            <td>
                <select>
                    <option value="1">上线</option>
                    <option value="2">下线</option>
                    <option value="3">注销</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><input type="checkbox"></td>
            <td>陈同学</td>
            <td>
                <select>
                    <option value="1">上线</option>
                    <option value="2">下线</option>
                    <option value="3">注销</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><input type="checkbox"></td>
            <td>李同学</td>
            <td>
                <select>
                    <option value="1">上线</option>
                    <option value="2">下线</option>
                    <option value="3">注销</option>
                </select>
            </td>
        </tr>
        </tbody>
    </table>
    <input type="button" id="b1" value="全选">
    <input type="button" id="b2" value="取消">
    <input type="button" id="b3" value="反选">
    <script src="jquery-3.4.1.min.js"></script>
    <script>) .on ("# b1"
        $ (Select All button events
        //"the Click " , function () { 
            $ ( " : the CheckBox " ) .prop ( " the checked " , to true); 
        });
         // Cancel button events 
        $ ( " # b2 " ) .on ( " the Click " , function () { 
            $ ( " : the CheckBox " ) .prop ( " the checked " , false); 
        });
         // Invert button events 
        $ ( " # b3 " ) .on ( " the Click " ,
            function () {
            //Find all checkbox, but this is a DOM object, attention turned JQuery object, and then modified for each checkbox checked with itself opposite value of 
            $ ( " : checkbox " ) .each (function () { 
                console.log (this) ; 
                var the flags = $ (the this) .prop ( " the checked " ); 
                $ (the this) .prop ( " the checked " , the flags!); 
            }); 
        });
         // shift-batch operation
         // definition of global variables, monitor whether the keyboard shift is pressed, a code corresponding shift is 16 
        var in Flag = to false;
         // monitor keyboard, note window object, e is the event itself 
        $ (window) .on ( " keyDown", function (E) {
             IF (e.keyCode === 16 ) { 
                In Flag = to true; 
            } 
        }); 
        $ (window) .on ( " keyUp " , function (E) {
             IF (16 === e.keyCode ) { 
                flag = to false; 
            } 
        });
         // SELECT binding change event 
        $ ( " Table SELECT " ) .on ( " change " , function () {
             // the flag is true, false determines whether or batch operation, but also determine whether the checkbox is checked
             if(In Flag) { 
                var selectValue = $ (the this) .val (); // the this value is modified select, val value obtained is a value option tag, while pass in this value, corresponding to the modified value will the corresponding content
                 // find all checkbox is selected the line select, select the specified value 
                $ ( " the INPUT: the checked " ) .parent () parent () the find (.. " the sELECT " ) .val (selectValue); 
            } 
        }) ;

     </ Script> 
    </ body> 
    </ HTML>

 

Guess you like

Origin www.cnblogs.com/god-for-speed/p/11587261.html