2016-04-24 24 views
0

這裏是我的JSP代碼如何通過字符串參數的onclick功能

<html> 
<head> 
<script> 
function updatestatus(str){ 
    //window.location.href="updatestatus.jsp?cid="+str; 
    alert(str); 
} 
function deletecompany(str1){ 
    alert(str1) 
    //window.location.href="deletecompany.jsp?cid="+str1; 
} 
</script> 
</head> 
<body> 
<% 
String status=request.getParameter("status"); 
//String id=request.getParameter("id"); 
String id="0005"; 
out.println(id); 
if(status.equals("approve")){ 
    out.println("<input type='button' value='update' onclick='updatestatus(\""+id+"\")'/>"); 
}else if(status.equals("reject")){ 
    out.println("<input type='button' value='delete' onclick='deletecompany(id)'/>"); 
} 
%> 
</body> 
</html> 

我可以得到兩種類型的按鈕,但,當我點擊沒有反應。我在函數括號內嘗試了很多參數格式,它們都不起作用......我不知道有什麼問題,你會給我一些建議嗎?

感謝您的關注 最好的問候;

+0

plz檢查頁面加載後的html代碼 –

回答

0

試試這個代碼片段:

<% 
String status = request.getParameter("status"); 
String id  = request.getParameter("id"); 
String value = null; 
String func = null; 

if (status.equals("approve")) { 
    value = "update"; 
    func = "updatestatus"; 
} else if (status.equals("reject")) { 
    value = "delete"; 
    func = "deletecompany"; 
} 
%> 
<input type='button' value='<%=value%>' onclick='<%=func%>("<%=id%>")'/> 

PS使用JSTL,而不是JSP腳本小程序。

+0

非常感謝你,我發現它將工作,如果我把函數放在onclick(),並且我嘗試if(status.equals(「批准」)){out.println (「」);} –

+0

然而它不起作用,我不知道是什麼是onclick函數內部的格式問題。謝謝你的幫助! –