<pre></pre>标签保留输入格式

本文详细介绍了HTML中pre元素的功能与使用方法,解释了如何利用<pre>标签保留文本的原始格式和空格,使得输入的文本能够原样输出,无需额外的换行或空格标记。

pre 元素可定义预格式化的文本。被包围在 pre 元素中的文本通常会保留空格和换行符。而文本也会呈现为等宽字体。

利用<pre></pre>这个标签可以将其包起来的文字排版、格式,原封不动的呈现出来。算是相当好用的标签之一。

也就是说你输入的东西被原封不动的输出,包括你输入的空格之类的,不用 <br>等来表示空格或者回车了

帮我添加注释<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>调查表单</title> <script src="js/vue.js"></script> <style> #user-from{ max-width: 600px; margin: 20px auto; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; } .from-group{ margin-bottom: 15px; } label{ display: block; margin-bottom: 5px; font-weight: 500; } .form-control{ width: 100%; padding: 8px 12px; border: 1px solid #ddd; } .radio-group, .checkbox-group{ display: flex; gap: 15px; } .radio-group label, .checkbox-group label{ display: flex; align-items: center; gap:5px; } .submit-btn{ background-color: #42b983; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 16px; } .submit-btn:disabled{ background-color: #cccccc; cursor: not-allowed; } .data-preview{ margin-top: 20px; padding: 15px; background-color: #f5f5f5; border-radius: 4px; } pre{ white-space: pre-wrap; word-wrap: break-word; } </style> </head> <body> <div id="user-from"> <h2>用户信息调查</h2> <form @submit.prevent="handleSubmit"> <div class="from-group"> <label>姓名:</label> <input type="text" v-model="userInfo.name" placeholder="请输入姓名" class="form-control"> </div> <div class="from-group"> <label>个人简介:</label> <textarea v-model="userInfo.bio" placeholder="请输入个人简介" class="form-control" rows="3"></textarea> </div> <div class="from-group"> <label>性别</label> <div class="radio-group"> <label> <input type="radio" value="male" v-model="userInfo.gender"> 男 </label> <label> <input type="radio" value="female" v-model="userInfo.gender"> 女 </label> </div> </div> <div class="from-group"> <label> <input type="checkbox" v-model="userInfo.agreeTerms" > 我已阅读并同意用户协议 </label> </div> <div class="from-group"> <label>兴趣爱好:</label> <div class="checkbox-group"> <label> <input type="checkbox" value="reading" v-model="userInfo.hobbies"/>阅读 </label><label for=""> <input type="checkbox" value="sports" v-model="userInfo.hobbies"/>运动 </label><label for=""> <input type="checkbox" value="coding" v-model="userInfo.hobbies"/>编程 </label><label for=""> <input type="checkbox" value="music" v-model="userInfo.hobbies"/>音乐 </label> </div> </div> <div class="from-group"> <label>职业:</label> <select v-model="userInfo.occupation" class="form-control"> <option value="">请选择职业</option> <option value="student">学生</option> <option value="teacher">教师</option> <option value="engineer">工程师</option> <option value="doctor">医生</option> <option value="other">其他</option> </select> </div> <button type="submit" class="submit-btn" :disabled= "!userInfo.agreeTerms">提交</button> </form> <div class="data-preview"> <h3>当前表单数据:</h3> <pre>{{userInfo}}</pre> </div> </div> <script> const app=new Vue({ el:"#user-from", data:{ userInfo:{ name:'', bio:'', gender:'male', agreeTerms: false, hobbies:[], occupation:'' } }, methods:{ handleSubmit(){ alert('表单提交成功 \n ' +JSON.stringify(this.userInfo,null,2)); } } }) </script> </body> </html>
09-27
<%-- Created by IntelliJ IDEA. User: Administrator Date: 2025/6/4 Time: 22:04 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page import="java.sql.*"%> <html> <head> <title>Title</title> <style> body{ background-color: aquamarine; } .main{ background-color: antiquewhite; margin:0 auto; width:60%; padding-left: 40px; padding-right: 40px; } .main div{ background-color: #F0F8FF; padding:10px; } </style> </head> <body> <% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("utf-8"); String bookid = request.getParameter("bookid"); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/book"; String un = "root"; String pass = "root"; Connection con = DriverManager.getConnection(url,un,pass); String sql = "select * from books where id = ?" ; PreparedStatement pre = con.prepareStatement(sql); pre.setString(1,bookid); ResultSet rs = pre.executeQuery(); while(rs.next()){ String id = rs.getString("id"); String urls = rs.getString("url"); String name = rs.getString("bookname"); String writer = rs.getString("writer"); String syn = rs.getString("syn"); float price = rs.getFloat("price"); String stock = rs.getString("stock"); %> <form action="BOOKXIUGAI_OK.jsp?id=<%=id%>" method="post"> <div class="main"> <img src="<%=urls%>" width="180" height="256" alt="图片"/> <div>图片:<input type="text" name="urls" value="<%=urls%>"></div> <div>ID:<input type="text" name="id" disabled="disabled" value="<%=id%>"></div> <div>商品名:<input type="text" name="name" value="<%=name%>"></div> <div>品类:<input type="text" name="writer" value="<%=writer%>"></div> <div>简介:<textarea type="text" name="syn" rows="4" cols="50"><%=syn%></textarea></div> <div>价格:<input type="text" name="price" value="<%=price%>">元/件</div> <div> 库存:<input type="text" name="stock" value="<%=stock%>"></div> <div> <input type="submit" name="submit" value="提交"></div> <div> <a href="REMOVEBOOKS.jsp?id=<%=id%>">删除此书</a></div> <div><hr></div> </div> </form> <% }pre.close();rs.close(); %> </body> </html> 简单优化一下要太复杂
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值