Last active
August 29, 2015 13:57
-
-
Save nagaki/9828581 to your computer and use it in GitHub Desktop.
気象庁の天気データ「日ごとの値」から、JavaScriptでデータを取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 気温 | |
var a = []; jQuery.each($('#tablefix1')[0].rows, function(i, val){ if(i > 3){a.push(parseFloat(val.cells[7].innerHTML));}}); console.log(a); | |
// 天気 | |
var a = []; jQuery.each($('#tablefix1')[0].rows, function(i, val){ if(i > 3){var s = val.cells[20].innerHTML[0]; var p; switch(s){ case "晴": case "快": p = 1; break; case "曇": p = 2; break; case "雨": case "雪": case "大": p = 3; break; default: p = 2;} a.push(p);}}); console.log(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 値を格納する為の配列を作成 | |
var a = []; | |
// テーブルの行を取得 | |
var rows = $('#tablefix1')[0].rows; | |
jQuery.each(rows, function(i, val) { | |
if (i > 3) { // ヘッダ行などをスキップ | |
// cellsの値からinnerHTMLでテキストを取得できる | |
a.push(parseFloat(val.cells[8].innerHTML)); | |
} | |
}); | |
console.log(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 値を格納する為の配列を作成 | |
var a = []; | |
// テーブルの行を取得 | |
var rows = $('#tablefix1')[0].rows; | |
jQuery.each(rows, function(i, val) { | |
if (i > 3) { // ヘッダ行などをスキップ | |
var p; | |
// 一文字目にフォーカスして[晴, 曇, 雨]を判定する | |
var s = val.cells[20].innerHTML[0]; | |
switch (s) { | |
case "晴": | |
case "快": | |
p = 1; | |
break; | |
case "曇": | |
p = 2; | |
break; | |
case "雨": | |
case "雪": | |
case "大": | |
p = 3; | |
break; | |
default: | |
p = 2; | |
} | |
a.push(p); | |
} | |
}); | |
console.log(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment