Brython中的JS函数

2024-05-15 05:53:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在中编写了一些简单的js函数对象.js文件,但我无法用python脚本访问它们

当我将所有代码从文件粘贴到索引.html,一切正常

如何从文件执行函数对象.js? 在

在索引.html公司名称:

<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<link rel="stylesheet" href="doc/doc_brython.css">
</head>

<body onload="brython({debug:1, cache:'none'})">
<canvas id="spriteCanvas" width="640" height="480" style="border:1px     solid #FF8844"></canvas>

<script type="text/javascript" src="objects.js"></script>
<script type="text/javascript" src="src/brython.js"></script>

<script type="text/python">
from browser import window
from browser import document as doc
pyjs=window

pyjs.create("instance",256,128);
pyjs.create("instance",256,256);
pyjs.create("player",128,256);
</script>
</body>
</html>

在对象.js公司名称:

^{pr2}$

Tags: 对象函数textsrc名称dochtmltype
2条回答

代码失败,因为变量instances未在中声明对象.js. 在

你想做什么并不明显

pyjs.create("instance",256,128)

在对象.js,create只接受一个参数。如果要将构造函数instance创建的对象传递给对象.js,可以在Brython代码中使用以下语法:

pyjs.create(pyjs.instance.new(256, 128));

函数“create”在本地js作用域中创建。试着

window.create = create

并在定义后可用

^{pr2}$

相关问题 更多 >

    热门问题