<html>
<head>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function(){
var index =0;
$('#textGroup :text').keydown(function(event){
var index =$(this).data('index');
if(event.which == 13){
$("#textGroup [data-index='"+ ++index +"']").focus();
}
});
$('#text1').click(function(event){
console.log('test click');
});
$('#add').click(function(){
var row =$('#textGroup2').html() +"<div><input type='text' data-index='"+ index++ +"' /></div>";
console.log(row);
$('#textGroup2').html(row);
$('#textGroup2 :text').on('keydown',function(event){
var index =$(this).data('index');
//console.log(index);
//console.log(event.which);
if(event.which==13){
$("#textGroup2 [data-index ='"+ ++index +"']").focus();
}
});
})
});
</script>
</head>
<body>
<div id="textGroup">
<input type ="text" id="text1" data-index="0" />
<input type ="text" data-index="1" />
<input type ="text" data-index="2" />
<input type ="text" data-index="3" />
</div >
<div id="textGroup2">
</div>
<button id="add" >add</button>
</body>
</html>