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 EventArgs() { // 자체 인수를 추가한 이벤트 핸들러 const current = (e, 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" onClick={e => current(e, 'datetime')}>현재 날짜 및 시각</button> <button id="date" onClick={e => current(e, 'date')}>현재 날짜</button> <button id="time" onClick={e => current(e, 'time')}>현재 시각</button> </div> ); } |