/*comment.js*/ ;(function($){ //消息显示 $.message=function(content){ $('#message').attr('data-content',content); $('#message').popover('show'); setTimeout(function() { $('#message').popover('hide'); },2000) } //隐藏标签 $.hidden = function(id){ var id = '#'+id; if(!$(id).hasClass('hidden')){ $(id).addClass('hidden'); } } //显示标签 $.display= function(id){ var id = '#'+id; if($(id).hasClass('hidden')){ $(id).removeClass('hidden'); } } function getCookie(name) { var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); return r ? r[1] : undefined; } //POST请求 $.postJSON = function(url, args, callback) { //args._xsrf = getCookie("_xsrf"); args.csrfmiddlewaretoken = getCookie("csrftoken"); $.ajax({url: url, data: $.param(args), dataType: "json", type: "POST", success: function(response) { callback(response); }}); }; })(jQuery);
使用
index.html
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="./comment.js"></script> </head> <body> test </body> </html>
标签:jquery,function,封装,getCookie,message,args,hidden,方法,id From: https://www.cnblogs.com/boye169/p/17605919.html