«   2020/01   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Archives
Today
50
Total
1,240,161
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

VanillaJS Form serialize() 본문

FrontEnd/JavaScript

VanillaJS Form serialize()

푸른바람 C/H 2019. 12. 16. 11:17
<form method="dialog">
  <p><label>Favorite animal:
    <select name="favAnimal" required>
      <option></option>
      <option>Brine shrimp</option>
      <option>Red panda</option>
      <option>Spider monkey</option>
    </select></label>
  </p>
  <p>
    <label>
      <input type="text" name="animallName" placeholder="animal name" value="Tiger" />
    </label>
  </p>
  <menu>
    <button>Cancel</button>
    <button>Confirm</button>
  </menu>
</form>
Array.from(document.querySelector('form')).map(item=>item.name?`${item.name}=${item.value}`:null).filter(item=>!!item).join('&')
// "favAnimal=&animallName=Tiger"

'FrontEnd > JavaScript' 카테고리의 다른 글

Javascript EventTarget()  (0) 2019.12.18
Canvas Tutorials  (0) 2019.12.17
VanillaJS Form serialize()  (0) 2019.12.16
JS Function.method  (0) 2019.12.11
JS Array.Method  (0) 2019.12.10
JS Array.prototype.reduce()  (0) 2019.12.09
0 Comments
댓글쓰기 폼