大虾,帮忙看一眼,就一眼!!!

lljllj2000 2001-11-09 09:54:42
<%@page contentType="text/html; charset=GB2312"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="javascript">
function save(id){
alert(id);
}
</script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--">
<%
String test="www";
%>
<input type="submit" value="提交" name="A" onclick="javascript:save(<%=test%>);">
</form>
</body>
</html>




为什么会出错呢?
而如果把test定义成中文或数字又都不一样了。
...全文
71 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
vincentmax 2001-11-10
  • 打赏
  • 举报
回复
知道是怎么回事吗?

因为,alert() 方法的入口参数必须是字符串,你在save(<%=test%>)的时候,系统本来打算显示表达式的值,就是说,当jsp页面被装入的时候会编译成“out.print(test)”的形式,而你又想将它做为入口参数,你就必须给它套上一对引号了。


解释的够清楚了吧 :)

大家讨论讨论,共同进步哈~~~~!
newhu 2001-11-09
  • 打赏
  • 举报
回复
onclick="javascript:save(<%=test%>);"
改成
onclick="javascript:save('<%=test%>');"

试一把,行不行?


redstarstar 2001-11-09
  • 打赏
  • 举报
回复
错误信息是什么?

cn_farmer 2001-11-09
  • 打赏
  • 举报
回复
嘿嘿!newhu is right
cn_farmer 2001-11-09
  • 打赏
  • 举报
回复
请注意你的jsp文件中:
<%
String test="www";
%>
格式不对!应为
<%!
String test="www";
%>

81,122

社区成员

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

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