본문 바로가기

프로그래밍

JavaScript - 텍스트와 아이디명 합친 오브젝트명 window[this.id + "Wrapper"]

출처 : http://devnote7.tistory.com 

* 사용법
window[this.id + "Wrapper"]

* 예제
<html>
<head>
<script type="text/javascript" language="javascript">
function test(){
    for ( i=0; i<3; i++ ){
        alert(document.all["test" + i].value);
    }
}
</script>
</head>
<body>
<input type="text" value="안녕하세요" id="test0" name="test0">
<input type="text" value="반갑습니다" id="test1" name="test1">
<input type="text" value="환영합니다" id="test2" name="test2">
<input type="button" value="테스트확인" onclick="javascript:test();">
</body>
</html>

* 결과