用py-script替换基本的JavaScript

huangapple go评论88阅读模式
英文:

Replacing basic Javascript with py-script

问题

以下是您要翻译的内容:

"是否可以用py-script Python代码替代基本的JavaScript代码(例如getElementById、addEventListener、checked、forEach等)?

我想在不学习JS的情况下与HTML一起工作,即使ChatGPT也没有帮助生成等效的Python代码。

示例:

<body>
<input class="checkbox-input" id="oranges" type="radio" />
<input class="checkbox-input" id="bananas" type="radio" />
<a href="#" id="clear-button">&nbspClear</a>
<script>
document.getElementById('clear- 
button').addEventListener('click', function () {
  ["oranges", "bananas"].forEach(function(id) {
    document.getElementById(id).checked = false;
  });
  return false;
})
</script>
</div>
</body>"
英文:

Is it possible to replace basic javascript (ex. getElementById, addEventListener, checked, forEach ...) with py-script Python codes ?

I want to work with html without learning JS, even ChatGPT didn't help to generate python equivalent code.

ex:

<body>
<input class="checkbox-input" id="oranges" type="radio" />
<input class="checkbox-input" id="bananas" type="radio" />
<a href="#" id="clear-button">&nbspClear</a>
<script>
document.getElementById('clear- 
button').addEventListener('click', function () {
  ["oranges", "bananas"].forEach(function(id) {
    document.getElementById(id).checked = false;
  });
  return false;
})
</script>
</div>
</body>

答案1

得分: 2

可以与DOM进行交互,在此答案中查看pyscript的方法。然而,所有文档、教程、书籍和在线课程都是针对原始JavaScript的。Pyscript仍然是一个小众领域。没有人会帮助你。如果你在web开发方面没有很强的背景,学习JavaScript并按照常见指南操作可能更容易。

英文:

It is possible to interact with DOM from pyscript - see this answer.

However, all documentation, tutorials, books and online courses are for vanilla JavaScript. Pyscript is still a niche. Nobody is going to help you. If you do not have strong background in web development, it is likely to be easier for you to learn JavaScript in the first place and follow the common guides.

huangapple
  • 本文由 发表于 2023年5月7日 17:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定