几个javascript的小方法

如何判断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);
View Code

如何禁用<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 });
View Code

 客户端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         }
View Code

 

转载于:https://www.cnblogs.com/mixls1234/p/3186078.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值