回答編集履歴
2
調整
answer
CHANGED
@@ -72,4 +72,82 @@
|
|
72
72
|
<input type="button" id="btn4" value="set green">
|
73
73
|
<input type="button" id="btn5" value="del green">
|
74
74
|
|
75
|
+
```
|
76
|
+
|
77
|
+
# 調整
|
78
|
+
```PHP
|
79
|
+
<?PHP
|
80
|
+
$cookie=filter_var_array($_COOKIE,["check_color"=>FILTER_DEFAULT]);
|
81
|
+
$checked=["red"=>"","green"=>""];
|
82
|
+
$val=["red"=>"","green"=>""];
|
83
|
+
print_r($cookie);
|
84
|
+
if(preg_match("/(^| )red(?= |$)/",$cookie["check_color"])){
|
85
|
+
$checked["red"]=" checked";
|
86
|
+
$val["red"]="red";
|
87
|
+
};
|
88
|
+
if(preg_match("/(^| )green(?= |$)/",$cookie["check_color"])){
|
89
|
+
$checked["green"]=" checked";
|
90
|
+
$val["green"]="green";
|
91
|
+
};
|
92
|
+
|
93
|
+
?>
|
94
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
95
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
|
96
|
+
<script>
|
97
|
+
$(function(){
|
98
|
+
//$.removeCookie('check_color');
|
99
|
+
console.log(document.cookie);
|
100
|
+
$('#btn1').on('click',function(){
|
101
|
+
location.href=location.href;
|
102
|
+
});
|
103
|
+
$('#btn2').on('click',function(){
|
104
|
+
setcolor('red');
|
105
|
+
});
|
106
|
+
$('#btn3').on('click',function(){
|
107
|
+
delcolor('red');
|
108
|
+
});
|
109
|
+
$('#btn4').on('click',function(){
|
110
|
+
setcolor('green');
|
111
|
+
});
|
112
|
+
$('#btn5').on('click',function(){
|
113
|
+
delcolor('green');
|
114
|
+
});
|
115
|
+
});
|
116
|
+
function setcolor(c){
|
117
|
+
var color=$.cookie('check_color')||'';
|
118
|
+
var reg=new RegExp("(^| )"+c+"(?= |$)");
|
119
|
+
if(!color.match(reg)){
|
120
|
+
if(color!=='') color+=' ';
|
121
|
+
color+=c;
|
122
|
+
$.cookie('check_color',color);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
function delcolor(c){
|
126
|
+
var color=$.cookie('check_color')||'';
|
127
|
+
var reg=new RegExp("(^| )"+c+"(?= |$)");
|
128
|
+
color=color.replace(reg,'');
|
129
|
+
color=color.replace(/^ | $/,'');
|
130
|
+
if(color==""){
|
131
|
+
$.removeCookie('check_color');
|
132
|
+
}else{
|
133
|
+
$.cookie('check_color',color);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
</script>
|
137
|
+
<div class="labels">
|
138
|
+
<label id="check_red">
|
139
|
+
<input name="check_red" type="checkbox" value="<?=$val["red"];?>"<?=$checked["red"];?>>
|
140
|
+
<span>red</span>
|
141
|
+
</label>
|
142
|
+
<label id="check_green">
|
143
|
+
<input name="check_red" type="checkbox" value="<?=$val["green"];?>"<?=$checked["green"];?>>
|
144
|
+
<span>green</span>
|
145
|
+
</label>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<input type="button" id="btn1" value="reload">
|
149
|
+
<input type="button" id="btn2"value="set red">
|
150
|
+
<input type="button" id="btn3" value="del red">
|
151
|
+
<input type="button" id="btn4" value="set green">
|
152
|
+
<input type="button" id="btn5" value="del green">
|
75
153
|
```
|
1
調整
answer
CHANGED
@@ -67,9 +67,9 @@
|
|
67
67
|
</div>
|
68
68
|
|
69
69
|
<input type="button" id="btn1" value="reload">
|
70
|
-
<input type="button" id="btn2"value="set
|
70
|
+
<input type="button" id="btn2"value="set red">
|
71
|
-
<input type="button" id="btn3" value="del
|
71
|
+
<input type="button" id="btn3" value="del red">
|
72
|
-
<input type="button" id="btn4" value="set
|
72
|
+
<input type="button" id="btn4" value="set green">
|
73
|
-
<input type="button" id="btn5" value="del
|
73
|
+
<input type="button" id="btn5" value="del green">
|
74
74
|
|
75
75
|
```
|