常用js方法合集

 1 var Default = {
 2     init: function () {
 3 
 4     },
 5     addCookie: function (name,data) {
 6         var expdate = new Date();   //初始化时间
 7         expdate.setTime(expdate.getTime() + 24 * 60 * 60 * 1000 * 30 * 100000);   //时间30天
 8         document.cookie = name + "=" + data + ";expires="+expdate.toGMTString()+";path=/";
 9     },
10     getCookie: function (name){
11         var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
12         if (arr = document.cookie.match(reg))
13             return arr[2].replace(/%3b/ig,';');
14         else
15             return null;
16     },
17     delCookie: function (sName) {
18         var date = new Date();
19         document.cookie = sName + "=;path=/;domain=eastmoney.com;expires=" + date.toGMTString();
20     }, 
21     backTop: function () {
22        var scrollTopNum = 0;
23        window.onscroll = function() {
24             if ($(window).scrollTop() > 10) {
25                 $('.gotop').show().unbind();
26                 $('.gotop').mousedown(function() {
27                     $('html,body').stop(0).animate({scrollTop : 0},200);
28                 });
29                 scrollTopNum = $(window).scrollTop();
30                 return;
31             } else{
32                 $('.gotop').hide();
33             };
34         }
35     },
36     dataTypeScript: function () {
37         $.ajax({
38             url: "xxxxxx",
39             type: 'GET',
40             dataType: 'script',    //dataType是script
41             data: {FCODES: FCODES,"callback":"fundData"},
42             success: function () {
43                 // 这个里面的值直接用变量传过来的
44                 // 直接用即可,比如传过来var data = {'aa':'123456'};
45                 // 那么直接取data的值即可
46             }
47         })
48     },
49     dataTypeJsonp: function () {
50         $.ajax({
51             type: "GET",
52             url: 'xxxxxx',
53             dataType: "jsonp",      //dataType是jsonp
54             jsonp: 'callback',      //需要指定
55             data: { uid: uid},
56             success: function (json) {
57                 // 用获取到的json
58             }
59         });
60     }
61 }
原文地址:https://www.cnblogs.com/marymei0107/p/7510744.html