请写一段html代码并美化,这段代码主要功能是显示两张表,表头分别是上料打标单元信息、JAKA机器人信息,两张表并排放,上料打标单元信息和JAKA机器人信息这两张表只有参数名和参数值两列,上料打标单元信息这张表参数名分别是打标机状态、打标内容,传送带状态,视觉检测设备状态;JAKA机器人信息这张表参数名分别是运行状态、轴1坐标信息。前端表格数据如何用ajax从后端获取,请写一段代码
时间: 2024-03-23 07:38:20 浏览: 117
好的,下面是这段完整的HTML代码,并使用CSS美化:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表格展示</title>
<style>
table {
border-collapse: collapse;
margin: 20px;
font-family: Arial, sans-serif;
border: 1px solid #ccc;
width: 40%;
float: left;
margin-right: 5%;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
h1 {
text-align: center;
margin-top: 50px;
}
.container {
margin: 50px 0;
width: 100%;
overflow: auto;
}
</style>
</head>
<body>
<h1>上料打标单元信息</h1>
<div class="container">
<table>
<thead>
<tr>
<th>参数名</th>
<th>参数值</th>
</tr>
</thead>
<tbody>
<tr>
<td>打标机状态</td>
<td>正常</td>
</tr>
<tr>
<td>打标内容</td>
<td>产品名称</td>
</tr>
<tr>
<td>传送带状态</td>
<td>运行中</td>
</tr>
<tr>
<td>视觉检测设备状态</td>
<td>正常</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>JAKA机器人信息</th>
</tr>
</thead>
<tbody>
<tr>
<td>运行状态</td>
<td>正常</td>
</tr>
<tr>
<td>轴1坐标信息</td>
<td>100</td>
</tr>
</tbody>
</table>
</div>
<!-- 用ajax从后端获取表格数据 -->
<script>
// 创建XMLHttpRequest对象
var xhr = new XMLHttpRequest();
// 监听状态改变事件
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// 获取后端返回的数据
var data = JSON.parse(xhr.responseText);
// 处理数据并渲染到表格中
// ...
}
};
// 发送GET请求
xhr.open('GET', '/api/tabledata', true);
xhr.send();
</script>
</body>
</html>
```
以上代码中,我使用了CSS样式来美化表格,使其看起来更加美观。同时,我还在页面底部加入了一段用Ajax从后端获取表格数据的代码,以便可以动态地更新表格内容。在实际使用时,需要将`/api/tabledata`修改为相应的接口地址,并在服务器端返回对应的表格数据。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)