All files / src/chap03 EventArgs2.js

0% Statements 0/11
0% Branches 0/3
0% Functions 0/2
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                 
export default function EventArgs2() {
  const current = e => {
    const type = e.target.dataset.type;
    const d = new Date();
    switch(type) {
      case 'date':
        console.log(`${e.target.id}: ${d.toLocaleDateString()}`);
        break;
      case 'time':
        console.log(`${e.target.id}: ${d.toLocaleTimeString()}`);
        break;
      default:
        console.log(`${e.target.id}: ${d.toLocaleString()}`);
        break;
    }
  };
  return (
    <div>
      {/* 출력할 날짜 및 시각 유형을 고유 데이터 속성으로 지정 */}
      <button id="dt" data-type="datetime" onClick={current}>현재 날짜 및 시각</button>
      <button id="date" data-type="date" onClick={current}>현재 날짜</button>
      <button id="time" data-type="time" onClick={current}>현재 시각</button>
    </div>
  );
}