更新
这是我尝试导出到Excel的表格:
<div id="dvData">
<table>
<tr>
<th>Photo No.</th>
<th>Vote Count</th>
</tr>
<tr>
<td>1</td>
<td id="result1" class="results">0</td>
</tr>
<tr>
<td>2</td>
<td id="result2" class="results">0</td>
</tr>
<tr>
<td>3</td>
<td id="result3" class="results">0</td>
</tr>
<tr>
<td>4</td>
<td id="result4" class="results">0</td>
</tr>
<tr>
<td>5</td>
<td id="result5" class="results">0</td>
</tr>
<tr>
<td>6</td>
<td id="result6" class="results">0</td>
</tr>
<tr>
<td>7</td>
<td id="result7" class="results">0</td>
</tr>
<tr>
<td>8</td>
<td id="result8" class="results">0</td>
</tr>
</table>
</div>
这是我尝试过的javascript
$(document).ready(function () {
function exportTableToCSV($table, filename) {
var $rows = $table.find('tr:has(td)'),
// Temporary delimiter characters unlikely to be typed by keyboard
// This is to avoid accidentally splitting the actual contents
tmpColDelim = String.fromCharCode(11), // vertical tab character
tmpRowDelim = String.fromCharCode(0), // null character
// actual delimiter characters for CSV format
colDelim = '","',
rowDelim = '"\r\n"',
// Grab text from table into CSV formatted string
csv = '"' + $rows.map(function (i, row) {
var $row = $(row),
$cols = $row.find('td');
return $cols.map(function (j, col) {
var $col = $(col),
text = $col.text();
return text.replace(/"/g, '""'); // escape double quotes
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowDelim)
.split(tmpColDelim).join(colDelim) + '"';
// Deliberate 'false', see comment below
if (false && window.navigator.msSaveBlob) {
var blob = new Blob([decodeURIComponent(csv)], {
type: 'text/csv;charset=utf8'
});
window.navigator.msSaveBlob(blob, filename);
} else if (window.Blob && window.URL) {
// HTML5 Blob
var blob = new Blob([csv], { type: 'text/csv;charset=utf8' });
var csvUrl = URL.createObjectURL(blob);
$(this)
.attr({
'download': filename,
'href': csvUrl
});
} else {
// Data URI
var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
$(this)
.attr({
'download': filename,
'href': csvData,
'target': '_blank'
});
}
}
$(".export").on('click', function (event) {
// CSV
var args = [$('#dvData>table'), 'export.csv'];
exportTableToCSV.apply(this, args);
// If CSV, don't do event.preventDefault() or return false
// We actually need this to be a typical hyperlink
});
});
上面的javascript只导出桌面上的csv文件,但是在iOS设备上,它只是打开另一个显示表数据的网页。有没有办法将其导出到iOS Excel应用程序?
<div id="box1">
<span id="result1" class="results">0</span>
</div>
<div id="box2">
<span id="result2" class="results">0</span>
</div>
我目前有一个带有以下JavaScript的点击计数器,当你点击该框时,该值将分别增加。
$( function() {
var clickCount = localStorage.getItem('clickCount');
clickCount = clickCount ? parseInt(clickCount) : 0;
var $num = $('#result1');
$num.text(clickCount);
$('#box1').click( function() {
$num.text(++clickCount);
localStorage.setItem('clickCount', clickCount);
document.getElementById("clicked").innerHTML = clickCount;
});
});
同时,我想将此值导出到iPad上的Excel应用程序,有什么方法可以解决这个问题吗?我尝试过的其他解决方案似乎只适用于桌面上的Excel。