I have a page user can dynamic add or edit html value like below, and I need to save it to database, I found a way- php read csv file and then update to database, but now my problem is
How to export html value(not table) to a csv file with jquery?
<div class="list">
<div class="number">1</div>
<div class="text">a</div>
<div class="text">a</div>
</div>
<div class="list">
<div class="number">1</div>
<div class="text">a</div>
<div class="text">a</div>
</div>
..
if you don't have comma-containing strings:
var csv = jQuery(".list").map(function(a,i){
return $.trim($(this).text()).split(/\s*\n\s*/).join(",");
}).toArray().join("\r\n");
alert(csv);
you can use my downloader at http://danml.com/js/download.js to download the csv variable like:
download(csv, "tabledata.csv", "text/csv");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.