質問するログイン新規登録

回答編集履歴

1

書式の改善

2016/08/03 11:12

投稿

masa128
masa128

スコア12

answer CHANGED
@@ -3,22 +3,24 @@
3
3
  ```javascript
4
4
  jQuery(function($) {
5
5
 
6
+ var url = location.protocol + "//" + location.host + location.pathname + location.search;
6
- var params = location.href.split('?');
7
+ var params = url.split('?');
7
8
  var paramms = params.length>1&&params[1].split('&');
8
9
  var paramArray = [];
9
10
  for(var i = 0; i < paramms.length; i++) {
10
11
  var vl = paramms[i].split('=');
11
12
  paramArray.push(vl[0]);
12
13
  paramArray[vl[0]] = vl[1];
14
+
15
+ var terms = decodeURIComponent(vl[1]);
16
+ $('input').each(function(){
17
+ var val = $(this).val();
18
+ if(terms === val) {
19
+ $(this).prop("checked",true);
20
+ }
21
+ });
22
+
13
23
  }
14
24
 
15
- params = decodeURIComponent(params);
16
- $('input[type=checkbox]').each(function(){
17
- var val = $(this).val();
18
- if(params.match(val)) {
19
- $(this).prop("checked",true);
20
- }
21
- });
22
-
23
25
  });
24
26
  ```