###■やりたいこと
次のテーブルの列をcookieに保存したいです。
保存したいのは「列」なのです。。
html
1<input type="button" id="c" class="btn" value="C" /> 2<input type="button" id="d" class="btn" value="D" /> 3 4<table> 5 <tr> 6 <td class="left">A1</td> 7 <td>B1</td> 8 <td class="c">C1</td> 9 <td class="d">D1</td> 10 </tr> 11 <tr> 12 <td class="left">A2</td> 13 <td>B2</td> 14 <td class="c">C2</td> 15 <td class="d">D2</td> 16 </tr> 17</table> 18 19<script> 20$(function() { 21 22 $('.btn').on('click', function(event) { 23 24 event.preventDefault(); 25 26 var id = $(this).attr('id'); 27 28 $('.' + id) 29 .toggle() //セルの表示切替 30 .each(function(){ //表示セルを左列に移動 31 if ($(this).css('display') == 'table-cell') 32 $(this) 33 .parent() 34 .find('.left') 35 .before(this) 36 .removeClass('left') 37 .end() 38 .end() 39 .addClass('left'); 40 }); 41 }); 42}); 43</script>
###■試したこと
「jqueryUI」の「sortable」を使ってみましたが、保存できたのは「行」で、「列」は保存できませんでした。
javascript
1$(function() { 2 $("#sortable").sortable( { 3 cursor: "move", 4 opacity: 0.7, 5 placeholder: "ui-state-highlight", 6 }); 7 $("#sortable").disableSelection(); 8 $(".btn").click(function() { 9 var updateArray = $("#sortable").sortable("toArray").join(","); 10 $.cookie("sortable", updateArray, {expires: 1}); 11 }); 12 13 if($.cookie("sortable")) { 14 var cookieValue = $.cookie("sortable").split(","); 15 $.each(cookieValue, function(index, value){ 16 $("#" + value).appendTo("#sortable"); 17 }); 18 } 19});

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/01 15:45
退会済みユーザー
2018/04/01 17:12
2018/04/01 22:09