[英]Wrong value in Javascript function param
I'm iterating over a list of object in c:foreach loop and creating a call to a javascript function that complete the length of my var an call server: 我要遍历c:foreach循环中的对象列表,并创建对javascript函数的调用,以完成我的var调用服务器的长度:
<c:forEach items="${clientList}" var="cli" varStatus="index">
...
<a href="javascript:goToClientDetail(${cli.client.PK})">
<img src="<%=imagesPath%>search.gif" width="14" height="14" border="0" align="absmiddle"/>
</a>
If I show ${cli.client.PK} in my .jsp I can see the correct value, but the problem is that the javascript function is getting a wrong value. 如果我在.jsp文件中显示$ {cli.client.PK},则可以看到正确的值,但是问题是javascript函数得到的值错误。
My JS function: 我的JS功能:
<script language="javascript">
function goToClientDetail(pk){
alert(pk);
var res = pk.toString();
while(res.length < 12){
res = '0'.concat(res);
}
document.getElementById('idlocalClient').value=res;
document.getElementById('fClientDetail').submit();
}
alert(pk)
shows different value that ${cli.client.PK}
in the .jsp alert(pk)
显示与.jsp中${cli.client.PK}
不同的值
Any hint? 有什么提示吗?
Have you tried putting single quotes around the ${cli.client.PK}
in the method call? 您是否尝试过在方法调用中在
${cli.client.PK}
周围加上单引号? JavaScript might try to use the value of the variable as a variable itself. JavaScript可能会尝试将变量的值用作变量本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.