zoukankan      html  css  js  c++  java
  • JavaScript & jQuery Code Snippet

    1. 按照每个object的Name属性对object对象集合进行排序;

                //sort a collection of objects by Name property
                function sortByItemName(originalObjects) {
                    var options = {};
    
                    $.each(originalObjects, function (index, item) {
                        options[item.Name] = item;
                    });
                    //sort() is case sensitive by default
                    var keys = Object.keys(options).sort(function (a, b) {
                        return a.toLowerCase().localeCompare(b.toLowerCase());
                    });
    
                    //get the results after sort
                    var sortedObjects = {};
                    $.each(keys, function (i, key) {
                        sortedObjects[i] = options[key];
                    });
                    return sortedObjects;
                }

    2. JavaScript中获取parameter的方法:

    function getQueryStrings(){
        var vars = [], hash;
        var q = document.URL.split('?')[1];
        if(q != undefined){
            q = q.split('&');
            for(var i = 0; i < q.length; i++){
                hash = q[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
        }
        return vars;
    }

    另一种方法:

    //name参数为需要查询的querystring的key
    function getQueryStringRegExp(name) {
            var reg = new RegExp("(^|\?|&)"
    + name + "=([^&]*)(\s|&|$)", "i");
            if (reg.test(location.href))
          return unescape(RegExp.$2.replace(/+/g, " "));
            return "";
        }

    3. 

  • 相关阅读:
    QPS的优化
    面试题
    py-redis
    集群化的部署
    RESTful设计
    python第三方库------jieba库(中文分词)
    csv文件读写处理
    python中的turtle库(图形绘画库)
    html中form表单的使用方法和介绍
    WC2019
  • 原文地址:https://www.cnblogs.com/qijiage/p/5168867.html
Copyright © 2011-2022 走看看