用户编辑的 JavaScript

发布于 2025-01-04 04:37:35 字数 148 浏览 2 评论 0原文

所以我想要的是有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

东京女 2025-01-11 04:37:35

eval (string) 将评估并执行 JavaScript 代码。

eval (string) will evaluate and excute the javascript code.

才能让你更想念 2025-01-11 04:37:35

使用 jQuery:

$(document).ready(function () { 
    $('button').click(function () {
        eval($('input').val());
        });
});

工作示例: http://jsfiddle.net/JL9EU/

Using jQuery:

$(document).ready(function () { 
    $('button').click(function () {
        eval($('input').val());
        });
});

Working example: http://jsfiddle.net/JL9EU/

谁人与我共长歌 2025-01-11 04:37:35

创建一个表单,将处理程序绑定到提交事件。在该处理程序中,执行代码并返回 false。

Create a form, bind a handler to the submit event. Within that handler, execute the code and return false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文