按格式回显<textarea/>中的内容

本文探讨了为何大部分程序员难以成为架构师的原因,并分享了两种处理文本显示的方法:一种是对空格和换行符进行特定的HTML实体替换;另一种则是直接使用&lt;textarea/&gt;标签来展示文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法一:对空格和换行符进行替换
String.valueOf(textareaContent.replaceAll(" ","&nbsp;").replaceAll("\\n","<br>"));

方法二:任然使用<textarea/>显示

转载于:https://my.oschina.net/chwencong/blog/55112

<meta charset="UTF-8"> <style> .container{ width: 40%; margin: 20px auto; } .common{ width:230px; height: 30px; } span{ display:inline-block; width: 150px; text-align: right; } div{ margin-bottom: 10px; } </style> <form class="container"> <div> <span>用户名:</span> <input type="text" class="common"> </div> <div> <span>昵称:</span> <input type="text" class="common"> </div> <div> <span>性别:</span> <input type="radio" id="male" name="sex"/> <label for="male">男</label> <input type="radio" id="female"/> <label for="female" name="sex">女</label> <input type="radio" id="other" disabled="disabled"/> <label for="other" name="sex">保密</label> </div> <div> <span>教育程度:</span> <select class="common"> <option >高中</option> <option >中专</option> <option >大专</option> <option selected="selected">本科</option> <option >硕士</option> <option >博士</option> <option >其他</option> </select> </div> <div> <span>婚姻状况:</span> <label for="single" name="state"> <input type="radio" checked="checked" id="single"/>未婚 </label> <label for="married" name="state"> <input type="radio" id="married"/>已婚 </label> <label for="secret" name="state"> <input type="radio" id="secret"/>保密 </label> </div> <div> <span>兴趣爱好:</span> <label for="football" name="hobby"> <input type="checkbox" id="football"/>踢足球 </label> <label for="basketball" name="hobby"> <input type="checkbox" id="basketball"/>打篮球 </label> <label for="film" name="hobby"> <input type="checkbox" id="film" checked="checked"/>看电影 </label> </div> <div> <span>描述自己的特点:</span> <textarea maxlength="20" class="common"></textarea> </div> <div> <span> </span> <input type="submit" value="提交" class="common"/> </div> </form>将以上代码语言改写为c语言
05-20
编程要求 本关要求补全右侧的代码,具体要求如下: 根据相关知识中介绍的验证方法,完成对必需字段的验证工作。 若内容输入无误,则在表单下方示输入的内容;反之给出相应提示。<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .error {color: #FF0000;} </style> </head> <body> <?php $nameErr = $emailErr = $genderErr = ''; $name = $email = $gender = $comment = $website = ''; /********** Begin *********/ /********** End *********/ function formatted_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <p> <span class="error">* 为必需字段</span> </p> <form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"> <label> 姓名:<input type="text" name="name"> </label> <span class="error">* <?php echo $nameErr;?></span> <br><br> <label> 邮箱:<input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span> </label> <br><br> <label> 博客:<input type="text" name="website"> </label> <br><br> <label> 备注:<textarea name="comment" rows="5" cols="40"></textarea> </label> <br><br> <label> 性别:<input type="radio" name="gender" value="male">男 <input type="radio" name="gender" value="female">女 <span class="error">* <?php echo $genderErr;?></span> </label> <br><br> <input type="submit" name="submit" value="提交"> </form> <?php echo '你输入的内容是:'."<br>"; echo $name."<br>"; echo $email."<br>"; echo $website."<br>"; echo $comment."<br>"; echo $gender."<br>"; ?> </body> </html>
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值