Git Product home page Git Product logo

angular-tutorial's Issues

js正则获取url的中的参数

            var getParam = function(name) {
            var search = document.location.search;
            var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
            var matcher = pattern.exec(search);
            var items = null;
            if (null != matcher) {
                try {
                    items = decodeURIComponent(decodeURIComponent(matcher[1]));
                } catch (e) {
                    try {
                        items = decodeURIComponent(matcher[1]);
                    } catch (e) {
                        items = matcher[1];
                    }
                }
            }
            return items;
        };
                //假设url为http://127.0.0.1/11/1.html?name=123
        window.mei = getParam('name'); //?name=123
        console.log(document.location.search); //123
        console.log(mei);

js操作cookie

function setCookie(name, value) {
            var Days = 30;
            var exp = new Date();
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        }
        setCookie('name', 'autumnswinds');
        console.log(document.cookie); //name=autumnswinds
        function getCookie(name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        }
        console.log(getCookie('name')); //autumnswinds
        function delCookie(name) {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = getCookie(name);
            if (cval != null)
                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
        }
        delCookie('name')
        console.log(document.cookie);

js理解观察者模式

function show(data) {
                $("body").append('<li>' + data + '</li>')
            }
            var Observable = {
                    callbacks: [],
                    add: function(fn) {
                        this.callbacks.push(fn);
                    },
                    fire: function() {
                        this.callbacks.forEach(function(fn) {
                            fn();
                        })
                    }
                }
                //使用add开始订阅:
            Observable.add(function() {
                show('AutumnsWind')
            })
            Observable.add(function() {
                show('AutumnsWinds')
            })
                //使用fire发布
            Observable.fire();

js数字比较的问题

        var order_amount = 18.00;
        var amount = 100.00
        console.log(typeof(order_amount)); //number
        console.log(typeof(amount));
        console.log(parseFloat(order_amount) >= parseFloat(amount));
        console.log(order_amount >= amount);    

        var order_amount_str = '18.00';
        var amount_str = "100.00"
        console.log(typeof(order_amount_str)); //string
        console.log(typeof(amount_str));
        console.log(parseFloat(order_amount_str) >= parseFloat(amount_str));
        console.log(order_amount_str >= amount_str);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.