小弟東湊西湊寫的, 程式碼部份copy下來 存成 classicgame.html 檔案 (部份程式碼無法正確顯示, 請改下載 zip 檔解開。), 用 Chrome 開啟,點日期輸入 才會出現日曆選擇

第一次認真寫的 html/javascript 處女作,請包涵。

點擊 URL 連結會以新視窗開啟 classic gameday。

有興趣者歡迎自行修改。

顯示如下 ===========================================================

MLB Classic Gameday URL 產生器

發現有部份程式碼無法正確顯示, 請下載 zip 檔。

附加壓縮檔: 201704/mobile01-fc4bebe7a12c330bea53c4f3b9547e4b.zip



<!-- MLB Classic Gameday URL generator
modify as you wish
-->
<!DOCTYPE html>
<html>
<head>
<title>MLB Classic Gameday URL Generator</title>
<style>
table {
padding: 8px;
}
th, td {
vertical-align: center;
border-bottom: 1px solid #ddd;
}
</style>
</head>
<body>

URL generator for MLB Teams's Classic Gameday







<label>Select a game date</label>


<input type="date" id="gamedt">

Input id for home team & guest team


Guest team: <input type="text" id="guest_id" />

Home team: <input type="text" id="home_id" />


<button onclick="generateURL()">Click to generate link</button>




var teams = [
"Angels" , "ana",
"Astros" , "hou",
"Athletics" , "oak",
"Blue Jays" , "tor",
"Braves" , "atl",
"Brewers" , "mil",
"Cardinals" , "sln",
"Cubs" , "chn",
"Diamond Backs" , "ari",
"Dodgers" , "lan",
"Giants" , "sfn",
"Indians" , "cle",
"Marlins" , "mia",
"Mariners" , "sea",
"Mets" , "nyn",

"Nationals" , "was",
"Orioles" , "bal",
"Padres" , "sdn",
"Phillies" , "phi",
"Pirates" , "pit",
"Rangers" , "tex",
"Rays" , "tba",
"Red Sox" , "bos",
"Reds" , "cin",
"Rockies" , "col",
"Royals" , "kca",
"Tigers" , "det",
"Twins" , "min",
"White Sox" , "cha",
"Yankees" , "nya"
];


<!-- functions block -->

function ListMLBTeams() {
var table = document.getElementById("myTable");


var i;
for ( i = 0; i < 15; i++) {<br>// value of 0 results in that the new row will be inserted at the first position.
// value of -1 results in that the new row will be inserted at the last position.
var row = table.insertRow();

var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
cell1[removed] = ( i + 1 ).toString();
cell2[removed] = "   " + teams[ i * 2 ];
cell3[removed] = "   " + teams[ i * 2 + 1 ];

cell4[removed] = "  |  ";

cell5[removed] = ( i + 16 ).toString();
cell6[removed] = "   " + teams[ i * 2 + 30 ];
cell7[removed] = "   " + teams[ i * 2 + 31 ];
}
}

function generateURL(){

// MLB classic gameday sample link:
// http://mlb.mlb.com/mlb/gameday/index.jsp?gid=2017_04_26_miamlb_phimlb_1&mode=classic

var url_head = "http://mlb.mlb.com/mlb/gameday/index.jsp?gid=";
var url_tail = "_1&mode=classic"
var date_str = "";
// ISO date format: YYYY-MM-DD
// replace character "-" with "_" globally
date_str = document.getElementById('gamedt').value.substring(0, 10).replace(/-/g, "_");

var guest_num = Number(document.getElementById('guest_id').value);
var home_num = Number(document.getElementById('home_id').value);

var guest_str = "_" + teams[(guest_num - 1) * 2 + 1]+ "mlb";
var home_str = "_" + teams[(home_num - 1) * 2 + 1] + "mlb";

var full_url = url_head + date_str + guest_str + home_str + url_tail
var title = "MLB Classic Gameday link";
var newwin_url = "" + title + ""

// display clickable URL that will open in a new window
document.getElementById("classic_url")[removed] = newwin_url;
}


<!-- main program -->

var gamedate;

ListMLBTeams();

Date.prototype.toDateInputValue = (function() {
var local = new Date(this);
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
return local.toJSON().slice(0,10);
});
// gamedate = document.getElementById("gamedt").value;
// set today's date as default
document.getElementById('gamedt').value = new Date().toDateInputValue();




</body>
</html>


文章關鍵字
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!