我用JSP做留言本

wind0209 2003-05-26 10:28:49
1。在我的发言的文本框里,提交后,我的回车存入数据库再读出来是不是就么效果了?是不是用JS在输入时替换一下?但是回车这时候是什么?/n吗?
谁能给个JS给我看看。
2。我读出数据显示在DIV里,DIV里怎么让它到一定长度,自己回车,不要把DIV拉长。
...全文
46 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wind0209 2003-05-27
  • 打赏
  • 举报
回复
先谢谢dkmilk(迪克牛奶),那第2个,不要让DIV随字符串长度变长而拉大是如何设的。
wind0209 2003-05-27
  • 打赏
  • 举报
回复
偶用
function change(text)
{
var r, re; // 声明变量。
re = /(\n)/g; // 创建正则表达式模式。
r = text.replace(re, "<br>"); // 交换每一对单词。
re=/(java)/g;
r=r.replace(re,"<b>j</b>ava");
return(r);
}
解决了,谢谢大家。
dkmilk 2003-05-26
  • 打赏
  • 举报
回复
存数据前不要作任何修改,

读取数据显示时要格式化
wind0209 2003-05-26
  • 打赏
  • 举报
回复
UP一下。
dkmilk 2003-05-26
  • 打赏
  • 举报
回复
public static String Replace(String source, String oldString, String newString) {
StringBuffer output = new StringBuffer();

int lengthOfSource = source.length(); // 源字符串长度
int lengthOfOld = oldString.length(); // 老字符串长度

int posStart = 0; // 开始搜索位置
int pos; // 搜索到老字符串的位置

while ((pos = source.indexOf(oldString, posStart)) >= 0) {
output.append(source.substring(posStart, pos));

output.append(newString);
posStart = pos + lengthOfOld;
}

if (posStart < lengthOfSource) {
output.append(source.substring(posStart));
}

return output.toString();
}

/*
public static String ReplaceIgnoreCase(String source, String oldString, String newString) {
}
*/

/**
* 将字符串格式化成 HTML 代码输出
* 只转换特殊字符,适合于 HTML 中的表单区域
*
* @param str 要格式化的字符串
* @return 格式化后的字符串
*/
public static String toHtmlInput(String str) {
if (str == null) return null;

String html = new String(str);

html = Replace(html, "&", "&");
html = Replace(html, "<", "<");
html = Replace(html, ">", ">");

return html;
}

/**
* 将字符串格式化成 HTML 代码输出
* 除普通特殊字符外,还对空格、制表符和换行进行转换,
* 以将内容格式化输出,
* 适合于 HTML 中的显示输出
*
* @param str 要格式化的字符串
* @return 格式化后的字符串
*/
public static String toHtml(String str) {
if (str == null) return null;

String html = new String(str);

html = toHtmlInput(html);
html = Replace(html, "\r\n", "\n");
html = Replace(html, "\n", "<br>\n");
html = Replace(html, "\t", " ");
html = Replace(html, " ", "  ");

return html;
}
wind0209 2003-05-26
  • 打赏
  • 举报
回复
UPUPUP
wind0209 2003-05-26
  • 打赏
  • 举报
回复
怎么格式化法,给个DEMO看看。

87,987

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧