본문 바로가기

카테고리 없음

Jquery 에서 clone 으로 추가한 div 객체 안의 input 태그 값 가져오기

728x90

Jquery 에서 clone 으로 추가한 div 객체 안의 input 태그 값 가져오기

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><spring:message code="approval.enforcepopup.title" /></title>
<link rel="stylesheet" type="text/css" href="/ep/app/ref/css/main.css" />
<script type="text/javascript" src="/ep/app/ref/js/jquery.js"></script>
<script type="text/javascript" >
var cnt=0
 function addDiv(){ 
 cnt++;
  var newDiv = $("#item"+cnt).clone(true);
  $(newDiv).attr("id", "item"+(cnt+1));
  newDiv.insertAfter("#item"+cnt);

  alert("item" + cnt + " code : " + $("#code", "#item"+cnt).val());
    
 }            
</script>
</head>      
<body>
<input type="button" onclick="addDiv()" value="add div">
 <div id="item1" width=50 height=50>
 <input type=text id="code" value="123"/>
 </div>
 
 
</body>
</html>

728x90