回答編集履歴

2

調整

2018/03/06 01:29

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -71,3 +71,71 @@
71
71
  console.log(str);
72
72
 
73
73
  ```
74
+
75
+
76
+
77
+ # 全体とおして
78
+
79
+ ```javascript
80
+
81
+ $(function(){
82
+
83
+ /* 置換 */
84
+
85
+ $('li.day a').each(function(){
86
+
87
+ $(this).text($(this).text().replace(/[0-9]/g,function(){
88
+
89
+ return String.fromCharCode((arguments[0].charCodeAt(0)-65248));
90
+
91
+ }).replace(/(\d+)月(\d+)日/,function(){
92
+
93
+ return arguments[1]+"/"+arguments[2];
94
+
95
+ }));
96
+
97
+ });
98
+
99
+ /* ソート */
100
+
101
+ $('li.day').get().sort(function(x,y){
102
+
103
+ var s=[x,y].map(function(z){
104
+
105
+ return $(z).find('a').text().replace(/(\d+)/(\d+)/,function(){
106
+
107
+ return ("0"+arguments[1]).substr(-2)+("0"+arguments[2]).substr(-2);
108
+
109
+ });
110
+
111
+ });
112
+
113
+ return s[0]>s[1];
114
+
115
+ }).forEach(function(x){
116
+
117
+ $(x).closest('.day-area').append(x);
118
+
119
+ });
120
+
121
+ });
122
+
123
+ ```
124
+
125
+ ```HTML
126
+
127
+ <div class="day-area">
128
+
129
+ <li class="day"><a href="xxx">1月1日</a></li>
130
+
131
+ <li class="day"><a href="xxx">2月1日</a></li>
132
+
133
+ <li class="day"><a href="xxx">1月2日</a></li>
134
+
135
+ <li class="day"><a href="xxx">10月1日</a></li>
136
+
137
+ <li class="day"><a href="xxx">1月12日</a></li>
138
+
139
+ </div>
140
+
141
+ ```

1

追記

2018/03/06 01:28

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -49,3 +49,25 @@
49
49
  </div>
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ # 全角→半角
56
+
57
+
58
+
59
+ UTF8であればこんな感じ
60
+
61
+ ```javascript
62
+
63
+ var str="0123987";
64
+
65
+ str=str.replace(/[0-9]/g,function(){
66
+
67
+ return String.fromCharCode((arguments[0].charCodeAt(0)-65248));
68
+
69
+ });
70
+
71
+ console.log(str);
72
+
73
+ ```