使用js时候在js方法的括号里加了一个对象进去,在js脚本里怎么调用方法里面的值?
<c:forEach items="${sessionScope.products }" var="p" varStatus="s">
<tr>
<td>${p.pid }</td>
<td>${p.pname }</td>
<td>${p.pcontext }</td>
<td><a href="javascript:showupd(${p })"onclick="">修改</a>|<a href="javascript:showdel()">删除</a></td>
</tr>
</c:forEach>function showupd(${p}){
alert("p");
//alert(p.pid);
document.getElementById("div_upd").style.display="";
document.getElementById("div_upd").style.top=y+"px";
document.getElementById("div_upd").style.left=x+25+"px";
}showupd()那个方法里怎么才能得到pid? javascript
[解决办法]
你这种方法是行不通的,你把前台js和后台java混淆了。
你可以通过隐藏域或者js的变量将pid等参数保存下来啊。
或者直接把这个方法改成
javascript:showupd(${p.id?},${p.name }, ${p.context})
把几个参数都传过去
function showupd(id,name,context){
alert("p.id="+id);
alert("p.name="+name);
alert("p.context="+context);
document.getElementById("div_upd").style.display="";
document.getElementById("div_upd").style.top=y+"px";
document.getElementById("div_upd").style.left=x+25+"px";
}
[解决办法]
javascript:showupd(${p.pid },${p.pname },${p.pcontext } 这样的形式传就好了。
[解决办法]
直接传进去不就得了?
<c:forEach items="${sessionScope.products }" var="p" varStatus="s">
<tr>
<td>${p.pid }</td>
<td>${p.pname }</td>
<td>${p.pcontext }</td>
<td><a href="javascript:showupd(${p.pid },${p.pname },${p.pcontext })"onclick="">修改</a>
[解决办法]
<a href="javascript:showdel()">删除</a></td>
</tr>
</c:forEach>
function showupd(pid,pname,pcontext){
alert(pid);
alert(pname);
alert(pcontext);
document.getElementById("div_upd").style.display="";
document.getElementById("div_upd").style.top=y+"px";
document.getElementById("div_upd").style.left=x+25+"px";
}