瀏覽代碼

add documentation

Falko Schindler 1 年之前
父節點
當前提交
1a3b1cedd8
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      website/documentation/content/generic_events_documentation.py

+ 12 - 0
website/documentation/content/generic_events_documentation.py

@@ -124,3 +124,15 @@ async def custom_events() -> None:
             }
         });
     ''')
+
+
+@doc.demo('Pure JavaScript events', '''
+    You can also use the `on` method to register a pure JavaScript event handler.
+    This can be useful if you want to call JavaScript code without sending any data to the server.
+    In this example we are using the `navigator.clipboard` API to copy a string to the clipboard.
+''')
+def pure_javascript() -> None:
+    ui.button('Copy to clipboard') \
+        .on('click', js_handler='''() => {
+            navigator.clipboard.writeText("Hello, NiceGUI!");
+        }''')