Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<div id="fre_table_label_20160627">
  <div>請輸入資料來源 (資料變更即輸出表格)</div>
<textarea id="fre_table_20160627"></textarea>  
  <div style="text-align:center;">
    <button type="button">輸入預設資料</button>
  </div>
</div>
<table id="output_20160627" border="1">
  <thead>
    <tr>
      <th>項目</th>
      <th>次數</th>
    </tr>
  </thead>
  <tbody></tbody>
</table>
<div style="clear:both"></div>
            
          
!
            
              #fre_table_label_20160627 {
  float:left;
  width: 30%;
}
#fre_table_20160627 {
  width: 90%;
  height: 20em;
}
            
          
!
            
              $(function () {
  $("#fre_table_20160627").change(function () {
    var _lines = $.trim(this.value).split("\n");
    var _list = {};
    for (var _i = 0; _i < _lines.length; _i++) {
        var _line = $.trim(_lines[_i]);
        if (typeof(_list[_line]) === "undefined") {
            _list[_line] = 1;
        }
        else {
            _list[_line] = _list[_line] + 1;
        }
    }

    var _sortable = [];
    for (var _item in _list) {
          _sortable.push([_item, _list[_item]])
    }
    _sortable.sort(
        function(a, b) {
            return b[1] - a[1]
        }
    )
    
    // 然後輸出表格
    var _tbody = $("#output_20160627 tbody");
    _tbody.empty();
    for (_i = 0; _i < _sortable.length; _i++) {
        var _item = _sortable[_i][0];
        var _count = _sortable[_i][1];
        var _tr = $("<tr></tr>").appendTo(_tbody);
        $('<td>' + _item + '</td>').appendTo(_tr);
        $('<td>' + _count + '</td>').appendTo(_tr);
    }
  });
  $("#fre_table_label_20160627 button").click(function () {
        $("#fre_table_20160627").val("生活風格\n文學\n文學\n文學\n醫療保健\n文學\n文學\n文學\n文學\n財經企管\n旅遊\n文學\n生活風格\n文學\n生活風格\n飲食料理\n旅遊\n心理勵志\n文學\n醫療保健\n旅遊\n文學\n旅遊\n財經企管\n飲食料理\n財經企管\n財經企管");                   
    $("#fre_table_20160627").change();
});
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console