JavaScript
[JavaScript] 동적으로 버튼 생성해주기
Fizzyelf
2022. 3. 21. 10:48
var html = '<button onclick="dosubmit('+id+', '+phNumber+', '+tall+', '+age+'), ">등록</button>';
$('').append(html);
이렇게 append 해줬을 때
만약 id의 값이 문자열이라면
onclick="example(java, 0 ,123, 44)"
이렇게 들어가기 때문에 버튼이 작동하지 않는다.
그렇기 때문에
var html = '<button onclick="dosubmit(\''+id+'\', '+phNumber+', '+tall+', '+age+'), ">등록</button>';
$('').append(html);
위와 같이 코드를 바꿔주면 잘 작동하는 것을 볼 수 있다.