这几天在学习JS,学习了一些之后,做了些实践.
脚本函数定义如下:
<script type = "text/javascript">
function confirminfo(code)
{
var r=confirm("是否确定?");
if (r==true)
{
document.write(code);
}
else
{
document.write("err");
}
}
</script>
脚本引用如下:
<html:button property = "button" onclick = "javascript:confirminfo(${pres.code})">
<bean:message key="del" />
</html:button>
发现当 ${pres.code} 的值为数值时,脚本可以正确执行,但是当其为字符串时,脚本就不能正确执行了。
于是修改代码如下:
<html:button property = "button" onclick = "javascript:confirminfo('${pres.code}')">
<bean:message key="del" />
</html:button>
在引用参数时加上引号即可。具体原因待查。