685600c41ad0b0c6477c5ec49c17387d1eade303.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. $.fn.extend({
  2. bindState: function(type, className, isBubble) {
  3. var $this = this;
  4. if (type == undefined) {
  5. type = 1;
  6. }
  7. if (className == undefined) {
  8. className = "";
  9. } else {
  10. className = className + "-";
  11. }
  12. if(isBubble==undefined){
  13. isBubble=false;
  14. }
  15. //绑定hover状态
  16. this.hover(function() {
  17. $(this).addClass(className + "hover");
  18. },
  19. function() {
  20. $(this).removeClass(className + "hover");
  21. });
  22. //点一下active,多个选择,点击选择,点击取消 复选
  23. if (type == 1 || type == "checkbox") {
  24. $(this).click(function(e) {
  25. $("."+className + "on").not($(this)).removeClass(className + "on");
  26. $(this).toggleClass(className + "on");
  27. if(isBubble){
  28. e.stopPropagation();
  29. }
  30. });
  31. } //点一下active,点击单个选择 单选
  32. else if (type == 2 || type == "radio") {
  33. $(this).click(function() {
  34. $this.removeClass(className + "on");
  35. $(this).addClass(className + "on");
  36. });
  37. } //点一下active,单个选择,再点一下取消 单选可取消选择
  38. else if (type == 3 || type == "toggle") {
  39. $(this).click(function() {
  40. var hasOn = $(this).hasClass(className + "on");
  41. $this.removeClass(className + "on");
  42. if (hasOn) {
  43. $(this).removeClass(className + "on");
  44. } else {
  45. $(this).addClass(className + "on");
  46. }
  47. });
  48. }
  49. }
  50. });
  51. ArrayindexOf = function(n,arr){
  52. var arrayStr = arr.join("#1#");
  53. return arrayStr.indexOf(n);
  54. /*if("indexOf" in this){
  55. return this["indexOf"](n);
  56. }
  57. for(var i=0;i<this.length;i++){
  58. if(n===this[i]){
  59. return i;
  60. }
  61. }
  62. return -1;*/
  63. };
  64. //js 阻止事件冒泡
  65. function stopProp (e) {
  66. //如果提供了事件对象,则这是一个非IE浏览器
  67. if ( e && e.stopPropagation )//因此它支持W3C的stopPropagation()方法
  68. e.stopPropagation();
  69. else//否则,我们需要使用IE的方式来取消事件冒泡
  70. window.event.cancelBubble = true;
  71. }
  72. Date.prototype.format = function (format) {
  73. /*
  74. * eg:format="yyyy-MM-dd hh:mm:ss";
  75. */
  76. function getWeekDay(weekNum){
  77. var weekDay="周";
  78. switch (weekNum) {
  79. case 1:
  80. weekDay += "一";
  81. break;
  82. case 2:
  83. weekDay += "二";
  84. break;
  85. case 3:
  86. weekDay += "三";
  87. break;
  88. case 4:
  89. weekDay += "四";
  90. break;
  91. case 5:
  92. weekDay += "五";
  93. break;
  94. case 6:
  95. weekDay += "六";
  96. break;
  97. default:
  98. weekDay += "日";
  99. break;
  100. }
  101. return weekDay;
  102. }
  103. var o = {
  104. "M+": (this.getMonth() + 1), // month
  105. "d+": this.getDate(), // day
  106. "h+": this.getHours(), // hour
  107. "m+": this.getMinutes(), // minute
  108. "s+": this.getSeconds(), // second
  109. "w+": getWeekDay(this.getDay()),
  110. "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
  111. "S": this.getMilliseconds() // millisecond
  112. };
  113. if (/(y+)/.test(format)) {
  114. format = format.replace(RegExp.$1, (this.getFullYear() + "")
  115. .substr(4 - RegExp.$1.length));
  116. }
  117. for (var k in o) {
  118. if (new RegExp("(" + k + ")").test(format)) {
  119. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
  120. : ("00" + o[k]).substr(("" + o[k]).length));
  121. }
  122. }
  123. return format;
  124. };