用户编辑的 JavaScript
所以我想要的是有一个 html 文本字段,人们可以在其中输入一些 JavaScript 代码,然后使用某种函数将其动态添加到我的网页的脚本标记中。有什么想法吗?
注意:我不希望任何内容永久保存到服务器,但我确实希望用户生成的 js 能够“工作”并与我当前的脚本交互。
So what I want is to have a html text field where someone can type in a bit of JavaScript code, and then some kind of function that will dynamically add it into the script tag of my webpage. Any ideas?
NOTE: I don't want anything saved permanently to the server, but I do want the user-generated js to "work" and interact with my current scripts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
eval (string) 将评估并执行 JavaScript 代码。
eval (string) will evaluate and excute the javascript code.
使用 jQuery:
工作示例: http://jsfiddle.net/JL9EU/
Using jQuery:
Working example: http://jsfiddle.net/JL9EU/
创建一个表单,将处理程序绑定到提交事件。在该处理程序中,执行代码并返回 false。
Create a form, bind a handler to the submit event. Within that handler, execute the code and return false.