如何判断js对象类似
1 (function ($) { 2 $.extend({ 3 GetType: function (x) { 4 if (x == null) { 5 return "null"; 6 } 7 var t = typeof x; 8 if (t != "object") { 9 return t; 10 } 11 var c = Object.prototype.toString.apply(x); 12 c = c.substring(8, c.length - 1); 13 if (c != "Object") { 14 return c; 15 } 16 if (x.constructor == Object) { 17 return c 18 } 19 if ("classname" in x.prototype.constructor 20 && typeof x.prototype.constructor.classname == "string") { 21 return x.constructor.prototype.classname; 22 } 23 return "<unknown type>"; 24 } 25 }); 26 })(jQuery);
如何禁用<a>标签
1 jQuery.fn.extend({ 2 disabledSuper: function (a, b) { 3 var id = this.get(0).id; 4 var html = $("#" + id).prop("outerHTML"); 5 if (html.indexOf("</a>") <= -1) { 6 $("#" + id).prop("disabled", b); 7 } 8 else { 9 var id = this.get(0).id; 10 var text = this.text(); 11 if (b) { 12 if ($("#" + id + "_disabled").length > 0) { 13 $("#" + id + "_disabled").show(); 14 } else { 15 this.after($("<a href='javascript:void(0)' id='" + id + "_disabled'>" + text + "</a>").css("color", "gray")); 16 } 17 this.hide(); 18 } else { 19 this.show().css("color", "black"); 20 $("#" + id + "_disabled").remove(); 21 } 22 } 23 } 24 });
客户端js取时区,精确到分钟
1 function clientTimeZone() { 2 3 var munites = new Date().getTimezoneOffset(); 4 5 var hour = parseInt(munites / 60); 6 7 var munite = munites % 60; 8 9 var prefix = "-"; 10 11 if (hour < 0 || munite < 0) { 12 13 prefix = "+"; 14 15 hour = -hour; 16 17 if (munite < 0) { 18 19 munite = -munite; 20 21 } 22 23 } 24 25 hour = hour + ""; 26 27 munite = munite + ""; 28 29 if (hour.length == 1) { 30 31 hour = "0" + hour; 32 33 } 34 35 if (munite.length == 1) { 36 37 munite = "0" + munite; 38 39 } 40 41 return prefix + hour + munite; 42 43 }
何时结束黑梦,迎接艳阳天?