zoukankan      html  css  js  c++  java
  • 常用Js笔记,以后可能用得上

      <div class="order_head">
                    <table>
                        <thead>
                            <tr>
                                <th class="talb1">
                                    商品
                                    <label><input type="checkbox" class="tgbox3">全选</label>
                                </th>
                                <th>价格</th>
                                <th>数量</th>
                                <th>总额</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div>
                        <table class="order_body">
                            <thead>
                                <tr>
                                    <th colspan="6">
                                        <div class="mergeckb">
                                            <input value="255" type="checkbox" class="tgbox" name="mk" />
                                        </div>
                                        <p>订单号:<i>DS180404111619136495</i></p>
                                        <p>下单时间:<i>2018/4/4 11:16:19</i></p>
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
    //关键字搜索
    $("#kwdKeyInput").focus(function () { document.onkeydown = function (evt) { var Withevt = (evt) ? evt : ((window.event) ? window.event : ""); var keyCode = Withevt.keyCode || Withevt.which || Withevt.charCode; if (keyCode == 13) { $('.or-search ul li button').trigger("click"); } } }) 
      //全选
        $(".tgbox3").click(function () {
            //取消全选
            if (!this.checked) {
                $('input[class="tgbox"]:checkbox:checked');
                var cboxs = $('input[class="tgbox"]:checkbox:checked');
                $.each(cboxs, function (index, e) {
                    removeToCookie($(e).val())
                });
            }
    
            $('.tgbox').prop("checked", this.checked);
            $(".many").text($("thead input[name='mk']:checked").length);
    
            var cboxs = $('input[class="tgbox"]:checkbox:checked');
            var cids = [];
            $.each(cboxs, function (index, e) {
                cids.push($(e).val());
            });
            addIdToCookie("," + cids);
        });
    //选框选中事件
    $('input[class="tgbox"]').click(function () {
            $(".tgbox3").prop("checked", $('input[name="mk"]').length == $('input[name="mk"]:checked').length);
    
            if (this.checked) {
                addIdToCookie("," + $(this).val());
            } else {
                removeToCookie($(this).val());
            }
        });
    //数组去重 
    function distinct(arr) {
            var len = arr.length;
            arr.sort();
            for (var i = len - 1; i > 0; i--) {
                if (arr[i] == "") { arr.splice(i, 1); }
                if (arr[i] == arr[i - 1]) {
                    arr.splice(i, 1);
                }
            }
            return arr;
        }
     //移除数组
        function removeToCookie(id) {
            var cookie = getCookie("orderIds") || "";
            var cookieArray = cookie.split(",");
            var idArray = id.split(",");
            if (cookie.indexOf(id) >= 0) {
                $.each(cookieArray, function (index, item) {
                    $.each(idArray, function (index2, iditem) {
                        if (iditem == item) {
                            cookieArray.splice(index, 1);
                        }
                    });
                });
    
                delCookie("orderIds");
                setCookie("orderIds", cookieArray.join(","), 10);
            }
    $(function () {
            //加载时选中之前选中项
            $('.tgbox').each(function () {
                var allCookie = getCookie("orderIds") || "";
                if (allCookie.indexOf($(this).val()) >= 0) {
                    $(this).prop('checked', true);
                }
            });
            //如果选中项等于当前表单所有项, 则说明是全选。
            $(".tgbox3").prop("checked", $('input[name="mk"]').length == $('input[name="mk"]:checked').length);
        })
    获取表单某个name为mk的input框
    
    $('input[name="mk"]')
    
    获取某个下拉框选中的文本/值
    
    $("#RemitCurrency option:selected").text()
    
    $("#RemitCurrency option:selected").val()
    
    获取单选框选中的值
    
    $('input:radio:checked').val()
  • 相关阅读:
    【Leetcode_easy】961. N-Repeated Element in Size 2N Array
    【Leetcode_easy】953. Verifying an Alien Dictionary
    【Leetcode_easy】949. Largest Time for Given Digits
    【Leetcode_easy】944. Delete Columns to Make Sorted
    【Leetcode_easy】942. DI String Match
    【Leetcode_easy】941. Valid Mountain Array
    【Leetcode_easy】938. Range Sum of BST
    【Leetcode_easy】937. Reorder Log Files
    【Leetcode_easy】933. Number of Recent Calls
    【Leetcode_easy】929. Unique Email Addresses
  • 原文地址:https://www.cnblogs.com/opts/p/9054754.html
Copyright © 2011-2022 走看看