【发布时间】:2017-11-27 19:48:59
【问题描述】:
似乎初始化 brython 需要这样做:
<body onload="brython()">
在链接 brython.js 后,我尝试在另一个 <script> 的 js 中调用 brython(),但它似乎没有被调用。
当我最终自己在浏览器控制台调用brython时,它调用了brython,甚至执行了我的python代码。
为了给出一个完整的例子来说明什么不起作用,这里有一个例子。我可能缺乏一些关于如何以及何时编译和执行 javascript 的基本知识......
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/js/brython.js"></script>
</head>
<!-- <body onload="brython()"> -->
<body>
<script type="text/javascript">
console.log("calling brython() here");
brython();
console.log("I just called brython()");
</script>
<script type="text/python">
from browser import document, alert
def echo(*args):
alert("Hello {} !".format(document["zone"].value))
document["test"].bind("click", echo)
print("what")
</script>
<p>Your name is : <input id="zone" autocomplete="off">
<button id="test">clic !</button>
</body>
</html>
【问题讨论】:
标签: javascript python html brython