Js 使用小技巧总结(1)

时间:2024-07-26 13:05:44

1.Js 的时间控制,小于初始时间,大于截止时间

<script type="text/javascript">
        window.onload = GameOver;
        function GameOver() {
            var startDate = new Date("2016-10-01 00:00:00");
            var endDate = new Date("2016-10-08 00:00:00");
            var currentData = new Date();
            if (currentData < startDate || currentData > endDate) {
                window.location.href = _urlBase + "/Shake/ShakeExcept";
            }
        }
    </script>

2.Js  简单访问监控代码

var _urlBase = "";
$(function () {
    $.ajax({
        url: _urlBase+'/pv',
        data: { fromUrl: window.location.href },
        datatype: 'json',
        type: 'post'
    });
});

3.获取URL参数

function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }

4. data-value='123'  获取

$("#tcContent").data('value'),