有没有办法在a href
jsp??
的特定功能
我的jsp代码是:
<%@include file="dbconnection.jsp"%>
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
<H1></H1>
<TABLE>
<%ResultSet resultset = statement.executeQuery("select DISTINCT title from categoryInfoTable;") ; %>
<% while(resultset.next()){ %>
<TR>
<script>
function <%=resultset.getString(1)%>() {
//////// Here i want to display data related to that particular link
}
</script>
<TD>
<a onclick="<%=resultset.getString(1)%>;" href="#"><%=resultset.getString(1)%></a>
</TD>
</TR>
<% } %>
</TABLE>
</BODY>
</HTML>
假设我从resulset.getString(1)
获得的链接名称是Audio
,那么我希望在点击Audio后,调用名为Audio的函数并在其中打印一些数据。我不想手动提供功能名称,因为我从resultset.getString(1)
获得了大约20个名字。
请帮帮我。
答案 0 :(得分:0)
试试这个代码段。对于所有20个案例,将计数器作为函数参数传递并在switch case中写入逻辑。
<script>
function displayData(ctr) {
//////// Here i want to display data related to that particular link
switch (ctr) {
case 0:
alert("function 1");
//write function logic here
break;
case 1:
alert("function 2");
break;
case 19:
alert("function 20");
break;
}
}
</script>
<TABLE>
<%ResultSet resultset = statement.executeQuery("select DISTINCT title from categoryInfoTable;") ; %>
<%
int counter=0;
while(resultset.next()){
String link=resultset.getString(1);
counter++;
%>
<TR>
<TD>
<a onclick="displayData(<%=counter%>);" href="#"><%=link%></a>
</TD>
</TR>
<% } %>
</TABLE>