英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论