上图是使用JavaScript上传到html页面的CSV文件的输出。
第1列:'名称',第2列:'电子邮件地址',第3列:'电话号码',第4列:'工作组'。
我添加了一个复选框来选择每一行,我还添加了一个“发送”按钮,将详细信息发送到另一个网页(php)。详细信息包括姓名和电子邮件地址(仅在选中时)应传递到其他页面。这可能吗? 上传代码的网址: Search and match CSV file values with javascript
答案 0 :(得分:1)
使用jQuery,您可以执行以下操作:
jQuery('form').submit(function(e){
// prevent the form from actually submitting
e.preventDefault();
var rows = [];
// get a handle to the form, then all checked checkboxes
// then back up to the rows and loop through each
jQuery(this).find(':checkbox:checked').closest('tr').each(function(){
var row = [];
// loop through all the cells that don't have a checkbox
// and get their text
jQuery.find('td:not(:has(:checkbox))').each(function(){
row.push(jQuery(this).text());
});
// join all the cell text together, separated by commas (you should
// probably also wrap each cell with double quotes to make sure
// commas in the text don't break the CSV)
rows.push(row.join(','));
});
// join all the rows together using new lines as separators
var csv = rows.join('\n');
// do what ya need to with the new CSV data, such as AJAXing it back
// to the server or submitting it as part of the form
});