0

我无法设置元素的 id。这是来自一个例子:

use wasm_bindgen::prelude::*;


#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
    let window = web_sys::window().expect("no global `window` exists");
    let document = window.document().expect("should have a document on window");
    let body = document.body().expect("document should have a body");

    let val = document.create_element("p")?;
    val.set_text_content(Some("Hello from Rust!"));

    val.id = "id_p";

    body.append_child(&val)?;
  

    Ok(())
}

线路val.id = "id_p";不工作。为什么?

4

0 回答 0