鱼C论坛

 找回密码
 立即注册
查看: 722|回复: 4

PyScript

[复制链接]
发表于 2024-4-27 22:05:59 | 显示全部楼层
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.       <meta charset="utf-8" />
  5.       <meta name="viewport" content="width=device-width,initial-scale=1" />
  6.       <title>&#129436; Polyglot - Piratical PyScript</title>
  7.       <link rel="stylesheet" href="https://pyscript.net/releases/2024.4.1/core.css">
  8.       <script type="module" src="https://pyscript.net/releases/2024.4.1/core.js"></script>
  9.   </head>
  10.   <body>

  11.     <!-- TODO: Fill in our custom application code here... -->
  12.     <button id="myButton">点击我!</button>

  13.     <script type="mpy">
  14.         # 导入所需的模块
  15.         from pyscript import document, window

  16.         # 定义回调函数
  17.         def handle_click(event):
  18.             window.alert("按钮被点击了!")

  19.         # 获取要监听的元素
  20.         button = document.getElementById("myButton")

  21.         # 在按钮上添加点击事件的监听器
  22.         button.addEventListener("click", handle_click)
  23.     </script>

  24.   </body>
  25. </html>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-29 02:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表