processing.js 更改脚本源

发布于 2025-01-03 05:57:56 字数 380 浏览 3 评论 0原文

我需要找到一种方法,可以动态更改 HTML 文档内的处理脚本的源。

这是运行良好的嵌入式脚本:

  <script type='application/processing' src='sketch.txt' id="applet">
  </script>

现在我尝试更改源:

  $('#applet').attr('src', 'sketch2.txt');
  alert($('#applet').attr('src'));

警报显示源已更改为“sketch2.txt”,但小程序仍然保持不变。我想我需要以某种方式刷新脚本。

预先感谢您的帮助!

I need to find a way where I can dynamically change the source of a processing script inside an HTML document.

This is the embedded script which works fine:

  <script type='application/processing' src='sketch.txt' id="applet">
  </script>

Now I try to change the source:

  $('#applet').attr('src', 'sketch2.txt');
  alert($('#applet').attr('src'));

The alert shows that the source was changed to 'sketch2.txt' but the applet still remains the same. I think I need to refresh the script in some way.

Thank you in advance for any help!

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

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

发布评论

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

评论(1

柒七 2025-01-10 05:57:56

我相信您必须手动将每个过程附加到画布,而不是仅仅更改源文件。这在这里起作用:

function first_call(processing) {
  processing.size(300,300);
  processing.background(100);
  var called = false;
  processing.draw = function() { 
    if (!called) { processing.println("called #1"); called = true; }
  }
}

function second_call(processing) {
  processing.size(400,400);
  processing.background(200);
  var called = false;
  processing.draw = function() {
    if (!called) { processing.println("called #2"); called = true; }
  }
}

var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, first_call);
var processingInstance = new Processing(canvas, second_call);

I believe you have to manually attach each proc to the canvas, instead of just changing the the source file. This worked here:

function first_call(processing) {
  processing.size(300,300);
  processing.background(100);
  var called = false;
  processing.draw = function() { 
    if (!called) { processing.println("called #1"); called = true; }
  }
}

function second_call(processing) {
  processing.size(400,400);
  processing.background(200);
  var called = false;
  processing.draw = function() {
    if (!called) { processing.println("called #2"); called = true; }
  }
}

var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, first_call);
var processingInstance = new Processing(canvas, second_call);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文