매일코딩/Node.js
[node js] 자바스크립트 동적구현&함수에 값넣고 호출 할때 에러해결
인생여희
2017. 6. 14. 18:43
동적쿼리 생성
output += '<a href="#" class="list-group-item"><img src="http://www.icons101.com/icons/2/facebook_ui_icons_vector_by_lopagof/128/list.png"; onclick="image(\'' + rows2[i].replyer + '\');" width="25" height="auto" class="img-responsive">';
<script>
function image(a){
//var a =$('#color').text();
alert(a)
</script>
}
문제는 음...
동적쿼리를 생성하고 ...
ajax로 값을 받아와서 동적 쿼리에 넣어 그 값을 함수에 던져준다...
숫자는 잘들어가지는데 문자를 던지니깐 계속 에러가 났다.
출력해보니..... undefind 하면서 정의 할 수 없다고..
3시간 넘게 삽질했다..
그래서 구글링!!!
인자 사이에 \'' 요런걸 넣어라네.....
갈길이 멀다.ㅠㅠ
*참고
accepted | You need to wrap the input item.store_code with quotation marks; otherwise, it tries to treat it as a variable, not a string: html += '<div class="col-sm-3"><input type="button" onclick="noActivationCodeRegistration(\'' + item.store_code + '\');" value="This Is My Store" data-store-code="' + item.store_code + '"></div>';
|