Jam's story

[JQuery] map() get() 본문

WEB/JQuery

[JQuery] map() get()

애플쩀 2022. 6. 14. 11:54
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>2022.06.14 11:46:55</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<h3>ex12.html</h3>
<form method="post" action="">
    <fieldset>
      <div>
        <label for="two">2</label>
        <input type="checkbox" value="2" id="two" name="number[]">
      </div>
      <div>
        <label for="four">4</label>
        <input type="checkbox" value="4" id="four" name="number[]">
      </div>
      <div>
        <label for="six">6</label>
        <input type="checkbox" value="6" id="six" name="number[]">
      </div>
      <div>
        <label for="eight">8</label>
        <input type="checkbox" value="8" id="eight" name="number[]">
      </div>
    </fieldset>
  </form>
  <script>
   var chbox_id_str= $( ":checkbox" )
  .map(function() {
    return this.id;
  })
  .get() //엘리먼트를 얻어옴 태그의 <시작></종료>
  .join(","); //요소들을 ,로 연결 
  console.log(chbox_id_str);
  </script>
</body>
</html>

Comments