似乎无法通过选择下拉列表来刷新它?
刚开始尝试学习这个
schedule.csv
码
var aval = 0;
function show(aval) {
sss()
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
(function sss() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = handleStateChange;
xhr.open("GET", "schedule.csv");
xhr.send();
function handleStateChange() {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 300) {
showData(xhr.responseText);
}
}
function showData(data) {
var rows = data.split(/\s+/);
var rowNum;
var cells;
var cellNum;
var team = 1 + aval*1;
var contents = "BEGIN:VCALENDAR\nPRODID:-//HullTenpin//EN\nVERSION:2.0\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nX-WR-CALNAME:Bowling\nX-WR-TIMEZONE:Europe/London\nX-WR-CALDESC:\n"
var table = document.createElement("table");
var rowss = data.split("\n");
for (var i = 3; i < rowss.length; i++) {
var row = table.insertRow(-1);
var cells = rowss[i].split(",");
var teamss = rowss[0].split(",");
var times = rowss[1].split(",");
var lanes = rowss[2].split(",");
var lanee = lanes[1].split(" - ");
var lane = lanee[0]*1 -1
for (var j = 0; j < cells.length; j++) {
var cell = row.insertCell(-1);
cell.innerHTML = cells[j];
var teams = cells[j].split("-");
var str1 = cells[0];
str1 = str1.replace (/st/g, "");
str1 = str1.replace (/nd/g, "");
str1 = str1.replace (/rd/g, "");
str1 = str1.replace (/th/g, "");
var locales = ["hu", "en-US"],
length = locales.length,
dateFormat = null;
var objDate = new Date(str1),
dateFormat = objDate.toLocaleString(locales[0], {
year: "numeric",
month: "numeric",
day: "numeric"
});
dateFormat = dateFormat.replace (/\./g, "");
dateFormat = dateFormat.replace (/ /g, "");
if (team == teams[0]){
var lanea = j*1 + lane*1 + (j - 1)
var laneb = j*1 + lane*1 + (j - 1)+ 1
var contents = contents + "BEGIN:VEVENT\n"
var contents = contents + "DTSTART:" + dateFormat + times[1] +"00Z\n";
var contents = contents + "DTEND:" + dateFormat + times[2] +"00Z\n";
var contents = contents + "LOCATION:Bowling Alley\n";
var contents = contents + "SUMMARY:" + teamss[team] + " V " + teamss[teams[1]] + " - Lanes " +"("+ lanea + ")"+"-" + laneb + "\n";
var contents = contents + "END:VEVENT\n"
}
if (team == teams[1]){
var lanea = j*1 + lane*1 + (j - 1)
var laneb = j*1 + lane*1 + (j - 1)+ 1
var contents = contents + "BEGIN:VEVENT\n"
var contents = contents + "DTSTART:" + dateFormat + times[1] +"00Z\n";
var contents = contents + "DTEND:" + dateFormat + times[2] +"00Z\n";
var contents = contents + "LOCATION:Bowling Alley\n";
var contents = contents + "SUMMARY:" + teamss[teams[0]] + " V " + teamss[team] + " - Lanes " + lanea + "-" +"("+ laneb+")" + "\n";
var contents = contents + "END:VEVENT\n"
}
}
}
var contents = contents + "END:VCALENDAR\n";
document.getElementById('area').value=contents;
for (var xx = 1; xx < teamss.length; xx++) {
var select = document.getElementById("purpose");
var el = document.createElement("option");
var opt = teamss[xx];
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
}
})();
</script>
<form onsubmit="download(this['name'].value, this['text'].value)">
<p><input type="text" name="name" value="schedule.ics"></p>
<fieldset>
<label>Pick a Team:</label>
<select name="Teams" id="purpose" onchange="java_script_:show(this.selectedIndex)"></select>
</fieldset>
<p><textarea rows=20 cols=100 id="area" name="text" ></textarea> </p>
<p><input type="submit" value="Download"></p>
</form>
已删除排序(来自函数ss()