Javascript 添加一行作为为将CSV表转换为HTML表而创建的表的标题
您好,我想添加一个加粗的静态行作为根据下面的脚本生成的表的标题,我不想将标题放在csv文件上,而是放在html文件本身上,这样,标题始终保持不变 多谢各位Javascript 添加一行作为为将CSV表转换为HTML表而创建的表的标题,javascript,html,ajax,csv,Javascript,Html,Ajax,Csv,您好,我想添加一个加粗的静态行作为根据下面的脚本生成的表的标题,我不想将标题放在csv文件上,而是放在html文件本身上,这样,标题始终保持不变 多谢各位 <!DOCTYPE html> <html> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></s
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="table-responsive">
<h1 align="center">CSV File to HTML Table Using AJAX jQuery</h1>
<br />
<div align="center">
<button type="button" name="load_data" id="load_data" class="btn btn-info">Load Data</button>
</div>
<br />
<div id="employee_table">
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#load_data').click(function(){
$.ajax({
url:"employee.csv",
dataType:"text",
success:function(data)
{
var employee_data = data.split(/\r?\n|\r/);
var table_data = '<table class="table table-bordered table-striped">';
for(var count = 0; count<employee_data.length; count++)
{
var cell_data = employee_data[count].split(",");
table_data += '<tr>';
for(var cell_count=0; cell_count<cell_data.length; cell_count++)
{
if(count === 0)
{
table_data += '<td>'+cell_data[cell_count]+'</td>';
}
else
{
table_data += '<td>'+cell_data[cell_count]+'</td>';
}
}
table_data += '</tr>';
}
table_data += '</table>';
$('#employee_table').html(table_data);
}
});
});
});
</script>
使用AJAX jQuery将CSV文件转换为HTML表
加载数据
$(文档).ready(函数(){
$(“#加载_数据”)。单击(函数(){
$.ajax({
url:“employee.csv”,
数据类型:“文本”,
成功:功能(数据)
{
var employee_data=data.split(/\r?\n | \r/);
var表_数据=“”;
对于(var count=0;count,在开始循环数据之前,您只需要在函数中添加一个静态头html元素
比如:
var table_data = '<table class="table table-bordered table-striped">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>';
var表\u数据=”
标题1
标题2
';