我需要找到一种方法,可以动态更改HTML文档中处理脚本的来源。
这是可以正常工作的嵌入式脚本:
<script type='application/processing' src='sketch.txt' id="applet">
</script>
现在我尝试更改来源:
$('#applet').attr('src', 'sketch2.txt');
alert($('#applet').attr('src'));
警报显示源已更改为“sketch2.txt”,但applet仍然保持不变。我想我需要以某种方式刷新脚本。
提前感谢您的帮助!
答案 0 :(得分:0)
我相信您必须手动将每个proc附加到画布,而不是仅仅更改源文件。这在这里工作:
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);