2014-11-08 57 views
-2

这里是我的代码:如何在JavaScript函数中传递字符串变量?

JSP:

String userId = rs.getString("user_id"); 

<center><a href="#" onclick="edit(\'' + userId + '\');">Edit</a></center> 

Javascrpt:

function edit(id) 
{ 
     alert(" user id is "+id); 

} 

,但它不工作。

提示错误:

Uncaught SyntaxError: Unexpected token ILLEGAL 
+1

可能重复的[从JavaScript读取的JSP变量(http://stackoverflow.com/questions/4803906/reading-a-jsp-variable-from-javascript ) – Surya 2014-11-08 10:41:16

+1

这是你试过编码吗?没有人会明白什么是实际问题。请发布一个代码,这里的每个人都可以了解什么是在这里调查 – 2014-11-08 10:41:51

+0

试试这个:

Edit
Amy 2014-11-08 10:43:29

回答

-2

哎FRINDS使用此代码的

<center><a href="#" onclick="edit( <%=userId %> ;">Edit</a></center> 
0

你需要这样做

var userId = '${userId}' <-- with ${} you get the var. 

或:

... onclick="edit('userId')" ... 


function edit(userId) { 
    var id = rs.getString(userId); 
    alert('id is: ' + id); 
} 

最好的问候。

相关问题