大神们!ajax 无刷新修改,为什么只支持数字,不支持中文?
index.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="adoconn.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jquery无刷新修改产品价格和数量</title>
<style type="text/css">
<!--
body{
font-size:12px;
}
.STYLE1 {
color: #FFFFFF;
font-weight: bold;
}
td{
font-size:12px;
}
-->
</style>
</head>
<!--
功能:jquery无刷新修改商品的数量和价格
来自:www.aspbc.com(asp编程网)
作者:wangsdong
原创文件,请保留此信息
-->
<body>
<a href="http://www.aspbc.com">进入ASP编程网</a><br />
<script language="javascript" src="jquery.js"></script>
<script language="javascript" src="modify.js"></script>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" align="center" bgcolor="#999999"><span class="STYLE1">编号</span></td>
<td align="center" bgcolor="#999999"><span class="STYLE1">产品名称</span></td>
<td align="center" bgcolor="#999999"><span class="STYLE1">价格</span></td>
<td align="center" bgcolor="#999999"><strong class="STYLE1">数量</strong></td>
<td align="center" bgcolor="#999999"><span class="STYLE1">时间</span></td>
</tr>
<%
set rs = server.createobject("adodb.recordset")
sql = "select gid,gname,gprice,gorder,gtime from [goods]"
rs.open sql,conn,1,1
if rs.eof then
else
do while not rs.eof
gid = rs("gid")
gname = rs("gname")
gprice = rs("gprice")
gorder = rs("gorder")
gtime = rs("gtime")
'******************下面是你要显示的******************
%>
<tr>
<td height="20" align="center"><%=gid%></td>
<td align="center"><%=gname%></td>
<td align="center">
<span id="gname1<%=gid%>" name="gname1<%=gid%>">
<input type="text" size="5" value="<%=gprice%>" maxlength="20" style="border:1px solid #FFFFFF; ime-mode:Disabled; color:#800000; font-weight:bold; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px; background-color:#FFFFFF; cursor:hand;" onClick="forder('<%=gid%>','<%=gprice%>','goods','gprice','gid','gname1');"></span></td>
<td align="center">
<span id="gname2<%=gid%>" name="gname2<%=gid%>">
<input type="text" size="5" value="<%=gorder%>" maxlength="20" style="border:1px solid #FFFFFF; ime-mode:Disabled; color:#800000; font-weight:bold; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px; background-color:#FFFFFF; cursor:hand;" onClick="forder('<%=gid%>','<%=gorder%>','goods','gorder','gid','gname2');"></span>
</td>
<td align="center"><%=gtime%></td>
</tr>
<%
'******************上面是你要显示的******************
rs.movenext
loop
end if
rs.close
%>
</table>
</body>
</html>
// JavaScript Document
/*
功能:jquery无刷新修改商品的数量和价格
来自:www.aspbc.com(asp编程网)
作者:wangsdong
原创文件,请保留此信息
*/
/*
id为要修改的记录ID
v是当前默认值
tablename表名
fname为字段名
gname为id的字段名
*/
function forder(id,v,tablename,fname,gname,str5)
{
str='<input type="text" size="3" value="'+id+'">';
str2='<input id="kk'+id+'" type="text" size="5" value="'+v+'" onblur="fchangeorder('+id+',this.value,'+v+',\''+tablename+'\',\''+fname+'\',\''+gname+'\',\''+str5+'\');">';
//alert(str2);
$("#"+str5+id).html(str2);
$("#kk"+id).focus();
$("#kk"+id).select();
}
/*
id为记录ID
v1为默认值
v为修改后的值
fname为字段名
gname为ID字段名,自动编号的那个字段的字段名
str5为页面上那个span的ID
*/
function fchangeorder(id,v,v1,t1,fname,gname,str5)
{
$.post("modify.asp",{id:id,v:v,t1:t1,fname:fname,gname:gname},
function(data){
if(data==1)
{
str='<input type="text" size="5" value="'+v+'" maxlength="20" style="border:1px solid #FFFFFF; ime-mode:Disabled; color:#800000; font-weight:bold; padding-left:4px; padding-right:4px; padding-top:1px; padding-bottom:1px; background-color:#FFFFFF; cursor:hand;" onClick="forder(\''+id+'\',\''+v+'\',\''+t1+'\',\''+fname+'\',\''+gname+'\',\''+str5+'\');">'
$("#"+str5+id).html(str);
}
else
{
$("#"+str5+id).html(v1);
}
}
);
}
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="adoconn.asp" -->
<%
'与javascript中的escape()等效
Function VbsEscape(str)
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf InStr("@*_+-./",c)>0 Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & "%u" & Hex(a)
End If
Next
VbsEscape=s
End Function
'与javascript中的unescape()等效
Function VbsUnEscape(str)
Dim x
x=InStr(str,"%")
Do While x>0
VbsUnEscape=VbsUnEscape&Mid(str,1,x-1)
If LCase(Mid(str,x+1,1))="u" Then
VbsUnEscape=VbsUnEscape&ChrW(CLng("&H"&Mid(str,x+2,4)))
str=Mid(str,x+6)
Else
VbsUnEscape=VbsUnEscape&Chr(CLng("&H"&Mid(str,x+1,2)))
str=Mid(str,x+3)
End If
x=InStr(str,"%")
Loop
VbsUnEscape=VbsUnEscape&str
End Function
id=request("id")
v=cstr(VbsUnEscape(request("v")))
t1=request("t1")
fname=request("fname")
gname=request("gname")
sql="update "&t1&" set "&fname&" = "&v&" where gid ="&id
'response.write sql
'response.end
conn.execute(sql)
response.write 1
%>