这段JavaScript代码有错吗?

来源:百度知道 编辑:UC知道 时间:2024/05/13 20:08:58
var sql = select top 10 newsid,title from news where "&Request.Cookies("uusername")&"<>'3' order by newsid";
var rs = conn.Execute(sql);
去掉where "&request.cookies("uusername")&"<>'3' 就正常,可我调用
<%=Request.Cookies("uusername")%>时有值。

var sql = "select top 10 newsid,title from news where " + Request.Cookies("uusername") + "<>'3' order by newsid";

& 符号是在 VBScript 中使用的, JavaScript 中使用 + 号连接字符串。

javascript里 不能用asp的代码啊··
要这样写·
var sql = select top 10 newsid,title from news where <%=Request.Cookies("uusername")%><>'3' order by newsid";

打开你的数据库,看看'3'对应的项是int类型还是文本类型。如果是int类型请不要用'',文本可以。

另外,建议不要使用cookies。

javascript语法不对。
1、字符串连接用"+"号。(vbscript才为"&"号);
2、不等号为"!="(vbscript才为"<>"号);
正确代码为:
var sql ="select top 10 newsid,title from news where "+Request.Cookies+"!='3' order by newsid";
相信你该知道:
“去掉where "&request.cookies("uusername")&"<>'3' 就正常,可我调用
<%=Request.Cookies("uusername")%>时有值。”
的原因了吧。