1

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

4

1 回答 1

0

当然有可能。有很多方法,其中一种方法是将要传递的变量附加到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);
于 2010-11-22T07:52:53.237 回答