``` <%@ page language="java" import="test_package.*" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="../style/certificate.css"> </head> <body> <% List<test_information> list = (List<test_information>)session.getAttribute("date"); %> <div class = "tit">查看凭证</div> <div class = "Ribbon"> <table> <tr> <td style="white-space: nowrap;"> <!-- 按钮1 --> <input type="button" value="传统记账" class="R_button"> <!-- 表单2 - 导出 --> <form action="" class="inline-form"> <input type="submit" value="导出" class="R_button"> </form> <!-- 表单3 - 打印 --> <form id="printForm" action="white.jsp" method="post" class="inline-form"> <input type="hidden" id="selectedTelsHiddenField" name="telsToPrint"> <input type="submit" value="打印" onclick="return submitSelectedTels();" class="R_button"> </form> <!-- 按钮4 --> <input type="button" value="模板" onclick="template.show()" class="R_button"> </td> <td> <input type = "text" name = "search_name"> <input type = "button" value = "搜索"> </td> </tr> </table> </div> <div class="body"> <table class="cer" > <% for(test_information news:list) { %> <!-- 将每条记录分为两列展示 --> <tr> <td class="zero_box"> <input type="checkbox" name="selectedTels" value="<%=news.getTel()%>" onchange="updateSelection(this)" style = "zoom : 300%"> </td> <td class="first_box"> <%= news.getMaterial() %> <br/> <%= news.getStart_time() %> </td> <td class="second_box"> <%= news.getWashing_method() %> <br/> <%= news.getPrice() %> </td> <td class="third_box"> <form action =""> <input name = "id" value ="<%=news.getTel() %>" type = "hidden"> <input type ="submit" class = "func_button" value = "税费" ><br> <input type ="submit" class = "func_button" value = "查看凭证" ><br> <input type ="submit" class = "func_button" value = "删除凭证" > </form> <br/> </td> </tr> <% } %> </table> <div style="display:none;" id="printArea"></div> </div> <script> let selectedTelsArray = []; function updateSelection(el) { if (el.checked && !selectedTelsArray.includes(el.value)) { // 如果当前被选中,则加入集合 selectedTelsArray.push(el.value); } else { // 否则移除该元素 const indexToRemove = selectedTelsArray.indexOf(el.value); if (indexToRemove !== -1) { selectedTelsArray.splice(indexToRemove, 1); } } console.log(selectedTelsArray); // 输出调试信息 } // 提交之前设置 hidden field 的值 function submitSelectedTels() { document.getElementById('selectedTelsHiddenField').value = JSON.stringify(selectedTelsArray); return true; } </script> </body> </html>```只修改search_text和search_button两个标签,实现让搜索框和搜索按钮在表格的右上角,和其余四个按钮平行
时间: 2025-03-17 11:14:27 浏览: 9
为了将 `search_text` 和 `search_button` 放置到表格的右上角,并与其他四个按钮保持水平对齐,可以调整 CSS 样式并重新组织 HTML 结构。
以下是修改后的代码片段:
### 修改部分
1. **CSS样式**:添加一个新的类 `.right-aligned` 来控制搜索框的位置。
2. **HTML结构调整**:将 `<input>` 元素移到合适位置并应用新的样式。
---
#### 修改后的完整代码
```html
<style>
.right-aligned {
text-align: right; /* 右对齐 */
}
.inline-form input[type=submit], .inline-form input[type=button] {
margin-left: 5px; /* 调整按钮之间的间距 */
}
</style>
<div class="Ribbon">
<table>
<tr>
<!-- 左侧按钮 -->
<td style="white-space: nowrap;">
<!-- 按钮1 -->
<input type="button" value="传统记账" class="R_button">
<!-- 表单2 - 导出 -->
<form action="" class="inline-form">
<input type="submit" value="导出" class="R_button">
</form>
<!-- 表单3 - 打印 -->
<form id="printForm" action="white.jsp" method="post" class="inline-form">
<input type="hidden" id="selectedTelsHiddenField" name="telsToPrint">
<input type="submit" value="打印" onclick="return submitSelectedTels();" class="R_button">
</form>
<!-- 按钮4 -->
<input type="button" value="模板" onclick="template.show()" class="R_button">
</td>
<!-- 右侧搜索框 -->
<td class="right-aligned">
<input type="text" name="search_name" placeholder="请输入关键字">
<input type="button" value="搜索" class="R_button">
</td>
</tr>
</table>
</div>
```
---
### 关键点解释
1. **`.right-aligned` 类**
- 使用 `text-align: right;` 让内容靠右显示。
2. **表结构优化**
- 利用 `<table>` 中的 `<td>` 分别放置左侧按钮组和右侧搜索框。通过独立单元格的方式确保两者互不影响。
3. **视觉效果**
- 确保搜索框和按钮与左侧行内元素在同一行,并且布局整齐美观。
---
### 效果图描述
- 页面顶部有一张包含左右两栏的表格。
- 左边是一排功能按钮(如“传统记账”、“导出”等),右边是对齐的输入框及“搜索”按钮。
---
阅读全文
相关推荐















