无法从servlet调用javascript [英] Cannot call javascript from from servlet

查看:79
本文介绍了无法从servlet调用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码创建了动态按钮。

I have made dynamic buttons, using this code.

out.print("<table>");
 out.print("<center><h1>Result:</h1></center>");
 rs=ps.executeQuery();                
 /* Printing column names */
 ResultSetMetaData rsmd=rs.getMetaData();
 out.print("<tr>");

 while(rs.next())
    {
     out.print("<td>"+rs.getString(2));              
     out.print("  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>");
     out.print(" <script src=\"js/index.js\"></script>");
     out.print("<button type=\"button\" onclick=friendnamebtn() id=\"btn_friends\">");
     out.print("Add" + rs.getString(2));
     out.print("</button>");
     out.print("</td></tr>");
 }
 out.print("</table>");    



我的javascript存储在index.js中


my javascript which is stored in index.js

function friendnamebtn()
{
     var friends = document.getElementById("btn_friends");
     alert(freinds+"add");
}



实际上,当我点击该按钮时,我希望获取该ID并将其添加到登录人的朋友列表中。我使用javascript调用了按钮事件如何连接这两个人。


Actually when i click on that button, i want that id to be fetched and add that persons to the logged in person's friend list. I called the buttons event using javascript how do i connect those two people.

推荐答案

这可能是因为你在声明javascript事件时错过了引用。你可以尝试这样的吗?



It may be because you are missing the Quote while declaring the javascript event. Can you try something like this?

out.print("<button type=\"button\" onclick='javascript:return friendnamebtn(this)' id=\"btn_friends\">");







function friendnamebtn(sender)
{
     //write your code here
     return false;
}


这篇关于无法从servlet调用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆