我的JavaScript函数是:如何通过jsp中的out.print将参数传递给JavaScript函数?
function f1(name){
alert("Hello "+name);
}
我的JSP代码:
<% out.print("<button onclick='f1(Rahul)'>Click me</button>"); %>
我的JavaScript函数是:如何通过jsp中的out.print将参数传递给JavaScript函数?
function f1(name){
alert("Hello "+name);
}
我的JSP代码:
<% out.print("<button onclick='f1(Rahul)'>Click me</button>"); %>
由于Rahul
是一个普通的String
你想/需要把它作为参数,你应该用引号(“)通过使用反斜线(\)字符转义:
<% out.print("<button onclick='f1(\"Rahul\")'>Click me</button>"); %>
^escape the quote
不过,因为你在JSP中是已经,你不需要写小脚本里面的HTML代码,这样你就可以将其更改为:
<%
...whatever code is here, probably a loop (very strange, indeed)
%>
<button onclick='f1("Rahul")'>Click me</button>
<%
rest of your scriptlet code...
%>
而你的问题是... –
我不能用参数调用函数f1():'Rahul' – RahulGoel
是'Rahul'的JSP变量或请求参数的名称? –