textarea 写入数据库的信息,在前台显示没有分段
(我是菜鸟,请用最简单的方法教我如果使用:str=str.replace(/\n+/g,"<br/>");)实现数据库读出时能正常换段!!整页代码如下:<%@LANGUA...
(我是菜鸟,请用最简单的方法教我如果使用:str=str.replace(/\n+/g,"<br/>");)实现数据库读出时能正常换段!!
整页代码如下:
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="../Connections/conn.asp" -->
<%
// *** Edit Operations: declare variables
// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}
// boolean to abort record edit
var MM_abortEdit = false;
// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables
if (String(Request("MM_insert")) == "form1") {
var MM_editConnection = MM_conn_STRING;
var MM_editTable = "xm12";
var MM_editRedirectUrl = "ok.asp";
var MM_fieldsStr = "xmname|value";
var MM_columnsStr = "xmname|',none,''";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it
if (String(Request("MM_insert")) != "undefined") {
// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "") + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";
if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}
}
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
</tr> <tr>
<td width="592"><form id="form1" name="form1" method="POST" action="<%=MM_editAction%>">
<p class="STYLE1">12、在建项目新增:</p>
<p><span class="STYLE1">项目名称:
<input name="xmname" type="text" id="xmname" />
</span></p>
<p>项目介绍:
<label>
<textarea name="content" id="content"></textarea>
</label>
</p>
<p><span class="STYLE1">
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</span>
<label> </label> </p>
<input type="hidden" name="MM_insert" value="form1">
</form> </td> </tr>
</table></body></html>
我是access数据库
没有任何报错,就是不知道怎么替换换行符等,怎么操作,在代码里加入什么,在哪加入代码 展开
整页代码如下:
<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="../Connections/conn.asp" -->
<%
// *** Edit Operations: declare variables
// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}
// boolean to abort record edit
var MM_abortEdit = false;
// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables
if (String(Request("MM_insert")) == "form1") {
var MM_editConnection = MM_conn_STRING;
var MM_editTable = "xm12";
var MM_editRedirectUrl = "ok.asp";
var MM_fieldsStr = "xmname|value";
var MM_columnsStr = "xmname|',none,''";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it
if (String(Request("MM_insert")) != "undefined") {
// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "") + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";
if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();
if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}
}
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
</tr> <tr>
<td width="592"><form id="form1" name="form1" method="POST" action="<%=MM_editAction%>">
<p class="STYLE1">12、在建项目新增:</p>
<p><span class="STYLE1">项目名称:
<input name="xmname" type="text" id="xmname" />
</span></p>
<p>项目介绍:
<label>
<textarea name="content" id="content"></textarea>
</label>
</p>
<p><span class="STYLE1">
<label>
<input type="submit" name="Submit" value="提交" />
</label>
</span>
<label> </label> </p>
<input type="hidden" name="MM_insert" value="form1">
</form> </td> </tr>
</table></body></html>
我是access数据库
没有任何报错,就是不知道怎么替换换行符等,怎么操作,在代码里加入什么,在哪加入代码 展开
1个回答
展开全部
如果你是放到textarea里,把内容直接赋就行了,如果是放到DIV,TD,里面的,把\n换成<br />就可以了,asp不熟悉,asp.net还好,建议到http://community.csdn.net里发问
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询