回答編集履歴
2
調整
test
CHANGED
@@ -147,3 +147,159 @@
|
|
147
147
|
|
148
148
|
|
149
149
|
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
# 調整
|
154
|
+
|
155
|
+
```PHP
|
156
|
+
|
157
|
+
<?PHP
|
158
|
+
|
159
|
+
$cookie=filter_var_array($_COOKIE,["check_color"=>FILTER_DEFAULT]);
|
160
|
+
|
161
|
+
$checked=["red"=>"","green"=>""];
|
162
|
+
|
163
|
+
$val=["red"=>"","green"=>""];
|
164
|
+
|
165
|
+
print_r($cookie);
|
166
|
+
|
167
|
+
if(preg_match("/(^| )red(?= |$)/",$cookie["check_color"])){
|
168
|
+
|
169
|
+
$checked["red"]=" checked";
|
170
|
+
|
171
|
+
$val["red"]="red";
|
172
|
+
|
173
|
+
};
|
174
|
+
|
175
|
+
if(preg_match("/(^| )green(?= |$)/",$cookie["check_color"])){
|
176
|
+
|
177
|
+
$checked["green"]=" checked";
|
178
|
+
|
179
|
+
$val["green"]="green";
|
180
|
+
|
181
|
+
};
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
?>
|
186
|
+
|
187
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
188
|
+
|
189
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
|
190
|
+
|
191
|
+
<script>
|
192
|
+
|
193
|
+
$(function(){
|
194
|
+
|
195
|
+
//$.removeCookie('check_color');
|
196
|
+
|
197
|
+
console.log(document.cookie);
|
198
|
+
|
199
|
+
$('#btn1').on('click',function(){
|
200
|
+
|
201
|
+
location.href=location.href;
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
$('#btn2').on('click',function(){
|
206
|
+
|
207
|
+
setcolor('red');
|
208
|
+
|
209
|
+
});
|
210
|
+
|
211
|
+
$('#btn3').on('click',function(){
|
212
|
+
|
213
|
+
delcolor('red');
|
214
|
+
|
215
|
+
});
|
216
|
+
|
217
|
+
$('#btn4').on('click',function(){
|
218
|
+
|
219
|
+
setcolor('green');
|
220
|
+
|
221
|
+
});
|
222
|
+
|
223
|
+
$('#btn5').on('click',function(){
|
224
|
+
|
225
|
+
delcolor('green');
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
});
|
230
|
+
|
231
|
+
function setcolor(c){
|
232
|
+
|
233
|
+
var color=$.cookie('check_color')||'';
|
234
|
+
|
235
|
+
var reg=new RegExp("(^| )"+c+"(?= |$)");
|
236
|
+
|
237
|
+
if(!color.match(reg)){
|
238
|
+
|
239
|
+
if(color!=='') color+=' ';
|
240
|
+
|
241
|
+
color+=c;
|
242
|
+
|
243
|
+
$.cookie('check_color',color);
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
function delcolor(c){
|
250
|
+
|
251
|
+
var color=$.cookie('check_color')||'';
|
252
|
+
|
253
|
+
var reg=new RegExp("(^| )"+c+"(?= |$)");
|
254
|
+
|
255
|
+
color=color.replace(reg,'');
|
256
|
+
|
257
|
+
color=color.replace(/^ | $/,'');
|
258
|
+
|
259
|
+
if(color==""){
|
260
|
+
|
261
|
+
$.removeCookie('check_color');
|
262
|
+
|
263
|
+
}else{
|
264
|
+
|
265
|
+
$.cookie('check_color',color);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
</script>
|
272
|
+
|
273
|
+
<div class="labels">
|
274
|
+
|
275
|
+
<label id="check_red">
|
276
|
+
|
277
|
+
<input name="check_red" type="checkbox" value="<?=$val["red"];?>"<?=$checked["red"];?>>
|
278
|
+
|
279
|
+
<span>red</span>
|
280
|
+
|
281
|
+
</label>
|
282
|
+
|
283
|
+
<label id="check_green">
|
284
|
+
|
285
|
+
<input name="check_red" type="checkbox" value="<?=$val["green"];?>"<?=$checked["green"];?>>
|
286
|
+
|
287
|
+
<span>green</span>
|
288
|
+
|
289
|
+
</label>
|
290
|
+
|
291
|
+
</div>
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
<input type="button" id="btn1" value="reload">
|
296
|
+
|
297
|
+
<input type="button" id="btn2"value="set red">
|
298
|
+
|
299
|
+
<input type="button" id="btn3" value="del red">
|
300
|
+
|
301
|
+
<input type="button" id="btn4" value="set green">
|
302
|
+
|
303
|
+
<input type="button" id="btn5" value="del green">
|
304
|
+
|
305
|
+
```
|
1
調整
test
CHANGED
@@ -136,13 +136,13 @@
|
|
136
136
|
|
137
137
|
<input type="button" id="btn1" value="reload">
|
138
138
|
|
139
|
-
<input type="button" id="btn2"value="set
|
139
|
+
<input type="button" id="btn2"value="set red">
|
140
140
|
|
141
|
-
<input type="button" id="btn3" value="del
|
141
|
+
<input type="button" id="btn3" value="del red">
|
142
142
|
|
143
|
-
<input type="button" id="btn4" value="set
|
143
|
+
<input type="button" id="btn4" value="set green">
|
144
144
|
|
145
|
-
<input type="button" id="btn5" value="del
|
145
|
+
<input type="button" id="btn5" value="del green">
|
146
146
|
|
147
147
|
|
148
148
|
|