Przeglądaj źródła

add `output.remove(anchor)`

wangweimin 5 lat temu
rodzic
commit
12298f2c2e
2 zmienionych plików z 9 dodań i 0 usunięć
  1. 2 0
      pywebio/html/js/pywebio.js
  2. 7 0
      pywebio/output.py

+ 2 - 0
pywebio/html/js/pywebio.js

@@ -259,6 +259,8 @@
                     console.warn(`clear_range not valid: can't find ${msg.spec.clear_range[1]} after ${msg.spec.clear_range[0]}`);
             }
         }
+        if (msg.spec.remove !== undefined)
+            this.container_elem.find(`#${msg.spec.remove}`).remove();
     };
 
     // 显示区按钮点击回调函数

+ 7 - 0
pywebio/output.py

@@ -12,6 +12,7 @@ r"""输出内容到用户浏览器
 .. autofunction:: clear_before
 .. autofunction:: clear_after
 .. autofunction:: clear_range
+.. autofunction:: remove
 .. autofunction:: scroll_to
 
 环境设置
@@ -95,6 +96,12 @@ def clear_range(start_anchor, end_anchor):
     send_msg('output_ctl', dict(clear_range=[inner_start_anchor_name, inner_end_ancher_name]))
 
 
+def remove(anchor):
+    """将 ``anchor`` 锚点连同锚点处的内容移除"""
+    inner_ancher_name = _AnchorTPL % anchor
+    send_msg('output_ctl', dict(remove=inner_ancher_name))
+
+
 def scroll_to(anchor, position=TOP):
     """将页面滚动到 ``anchor`` 锚点处