fork download
  1. <script>
  2.  
  3. addEventListener('DOMContentLoaded', function () {
  4.  
  5. var jyunjo = ["緑", "赤", "青"]
  6.  
  7. var tds = document.querySelectorAll('#TB td')
  8. var texts = [].map.call(tds, function (e) {return e.textContent})
  9.  
  10. function observer(recs) {
  11. recs.forEach(function (rec) {
  12. tds[rec.name].textContent = texts[rec.name]
  13. })
  14. }
  15.  
  16. Object.observe(texts, observer);
  17.  
  18. texts.sort(function (a, b) {
  19. Object.deliverChangeRecords(observer)
  20. //return jyunjo.indexOf(a) > jyunjo.indexOf(b) //その他は前に
  21. return (jyunjo.indexOf(a)+1 || 1/0) > (jyunjo.indexOf(b)+1 || 1/0) //その他は後ろに
  22. })
  23.  
  24. })
  25.  
  26. </script>
  27.  
  28.  
  29. <table id='TB'><tr>
  30. <td>青</td>
  31. <td>赤</td>
  32. <td>他</td>
  33. <td>赤</td>
  34. <td>青</td>
  35. <td>緑</td>
  36. <td>他</td>
  37. <td>緑</td>
  38. </tr></table>
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty