📌  相关文章
📜  如何在javascript代码示例中获取所有表单值

📅  最后修改于: 2022-03-11 15:02:36.789000             🧑  作者: Mango

代码示例1
//target the element and set submit event
    document.querySelector("form").addEventListener("submit", handleSubmit);

    //event function
    const handleSubmit = (e) => {
        e.preventDefault();
        let data = [...e.currentTarget.elements]
            .filter((ele) => ele.type !== "submit")
            .map((ele) => {
                return {
                    [ele.getAttribute("name")]: ele.type === "file" ? ele.files : ele.value,
                };
            });
        console.log(data);
    };