jsp传值给js,请解答
validateCodeCreate.jsp内容如下:
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@include file="../basepath.jsp"%>
<title>ValidateCodeCreatel.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="${pageContext.request.contextPath }/js/vote/vote.js"></script>
</head>
<body>
<%
String sessionKey = null;
try
{sessionKey = request.getParameter("sessionKey");}
catch(Exception e)
{sessionKey = "validateCodeSessionKey";}
%>
<script language="javascript"> var strcode="${sessionKey}";</script>
<img id="validateImg" style="cursor:pointer" src="ValidataCodeImg?sessionKey=<%=sessionKey%>" alt="看不清点我" border="0" onClick="location.reload()"><br/>
</body>
</html>
js文件vote.js如下
function doSubmit(count) {
if ($("#validateCode").val() == "") {
alert("验证码不能为空!");
$("#validateCode").focus();
return;
}
if ($("#validateCode").val() != "1234")//需要得到生成的验证码
{
alert("验证码错误!");
$("#validateCode").focus();
return;
}
var checkbox = $(":checkbox");
var flag = 0;
checkbox.each(function(i) {
if ($(this).attr("checked") == true) {
flag ++;
}
});
if(flag == 0)
{
jAlert("请先选择作品!");
return;
}
if(flag > count)
{
jAlert("您的票数不够!");
return;
}else {
$('#myForm').submit();
}
}
如何将validateCodeCreate.jsp的sessionKey变量传递给vote.js并放在if ($("#validateCode").val() != "1234")//需要得到生成的验证码只能够,替代"1234"