How to get a Object from inputs in vanilla javascript

后端 未结 3 592
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 22:35

For exemple, i have 3 inputs





        
3条回答
  •  我在风中等你
    2021-01-16 23:18

    You should use a JavaScript object with dynamic property names:

    var obj = {};
    document.querySelectorAll("input").forEach(input => obj[input.name] = input.value);
    console.log(obj);
    
    
    

提交回复
热议问题