如何将input事件侦听器添加到HtmlInputElement/ HtmlTextAreaElement。我正在使用web-sys并阅读this,但是在此之后,我在闭包内使用的所有元素(在这种情况下尤其是input元素)都被移动到闭包中,之后我无法附加侦听器。
let closure = Closure::wrap(Box::new(|_: web_sys::InputEvent| {
console_log!("{}", input.value());
}) as Box<dyn FnMut(_)>);
input.add_event_listener_with_callback("input", closure.as_ref().unchecked_ref())?;
// ^
// Doesn't work because the `input` variable was moved into the closure.
具体来说,我得到:
borrow of moved value: `input`