[英]Alert box doesn't display anything
JSP是:
<input type="submit" value="GENERATE TICKET" class="button" name="generate" onclick="myFunction()">
<script>
function myFunction() {
alert(
<%SelectCustomer sc = new SelectCustomer();
System.out.println(sc.getCash());%>
);
}
</script>
Java类是:
public class SelectCustomer
{
public int getCash() throws SQlException
{
return 12;
}
}
警报框弹出,但为空白。 是什么原因? 如何在警告框中打印12?
尝试使用<%= %>
而不是<% %>
。
还要确保在警报函数调用中使用引号。
尝试这段代码添加一个隐藏的输入,如果您想要的值
<input type='hidden' name='' id='data' value=' <%= VALUE-HERE %>' />
然后JS:
var content =document.getElementById('data').getAttribute('value');
alert(content);
请尝试使用以下脚本:
<script>
function myFunction() {
<% Windowlogin sc = new Windowlogin();%>
alert(<%=sc.getCash()%>);
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.