未捕获的ReferenceError:未定义daisy [英] Uncaught ReferenceError: daisy is not defined

查看:104
本文介绍了未捕获的ReferenceError:未定义daisy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

code

 while(rs.next())
                        {
                         String friendname = rs.getString(2);
                         
                         out.print("<table><tbody><tr><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("<button type=\"button\" onclick='javascript:return friendnamebtn(this)' id=\"btn_friends\">");
                         out.print("<button type=\"button\" onclick='javascript:return friendnamebtn("+ friendname +")' id=\"btn_friends\">");
                         out.print("Add" + friendname);
                         out.print("</button>");
                         out.print("</td></tr></tbody></table>");
               
                     }
                     out.print(""); 

javascript code

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

推荐答案

您需要在 friendname 周围加上引号 onclick 所以它也是正确的javascript。如果你查看生成的html / javascript混音,你会发现错误。这就是为什么通过粘贴html,javascript和值来创建网站,希望有效的东西只是找麻烦。



顺便说一下,这很奇怪在td元素中添加脚本元素。将该值放入 friendname 后,使用 rs.getString(2)也很奇怪。这表明一些草率的编码。但真正令人担心的是只需将 rs.getString(2)直接保存在您的响应中,而无需先对其进行html编码。



祝你好运!
You need to put quotes around friendname in the onclick so it is also correct javascript. If you look at the resulting html/javascript mix you'll notice the error. This is why creating websites by pasting html, javascript and values together in hope of something that works is just looking for trouble.

By the way, it is pretty strange to add your script element in a td element. It is also strange you use rs.getString(2) after you put that value in friendname. This indicates some sloppy coding. But what's really to worry about is just putting whatever rs.getString(2) holds directly in your response without html encoding it first.

Good luck!


这篇关于未捕获的ReferenceError:未定义daisy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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