Javascript 或 jQuery 获取Processingjs 变量?

发布于 2024-10-04 01:52:37 字数 132 浏览 4 评论 0原文

是否可以将变量 processingjs 传递到 Javascript / jQuery 以在 AJAX 发送到服务器中使用

Is it possible to pass a variable from processingjs to Javascript / jQuery for use in AJAX send to server

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

墨洒年华 2024-10-11 01:52:37

当然有可能。有很多方法,其中一种方法是将您希望传递的变量附加到 window 对象。这不是唯一的解决方案,也绝对不是最优雅的解决方案,但是它确实有效。

所以像这样:

// processingjs code...
window.varIWantToPassAround = "whatever"; 

// jQuery code... 
// as long as you don't redefine the variable "varIWantToPassAround", you can reference it without referencing the window object. IE "window.varIWantToPassAround"
// but I like to be explicit so when I read my code 3 months later and go "where did *that* come from, I can see it is attached to the window object.
$("#unicorn_powerd_div").someFunctionThatGrowsMagicUnicorns(window.varIWantToPassAround);

Sure it's possible. There are many ways, one of the ways is to attach the variable you wish to pass around to the window object. It's not the only solution and definitely not the most elegant solution, but, it works.

So something like this:

// processingjs code...
window.varIWantToPassAround = "whatever"; 

// jQuery code... 
// as long as you don't redefine the variable "varIWantToPassAround", you can reference it without referencing the window object. IE "window.varIWantToPassAround"
// but I like to be explicit so when I read my code 3 months later and go "where did *that* come from, I can see it is attached to the window object.
$("#unicorn_powerd_div").someFunctionThatGrowsMagicUnicorns(window.varIWantToPassAround);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文