簡體   English   中英

如何在onclick函數中傳遞字符串參數

[英]how to pass string parameter in onclick function

這是我的jsp代碼

<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>

我可以得到兩種類型的按鈕,但是單擊時沒有任何反應。 我已經在功能括號內嘗試了許多參數格式,但它們都不起作用...我想知道是什么問題,您能給我一些建議嗎?

謝謝您的關心和問候!

嘗試以下代碼片段:

<%
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 scriptlet。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM