2012-12-16 9 views
0

나는 루프가 PHP foreach 인 테이블을 만들었습니다. 이제는 td의 값을 input으로 바꾸려고합니다.<input> 포커스 손실

$('#memberTable tr td').click(function(e){ 
    $(this).html('<input type="text" id="" size="20" value=""/>'); 
}); 

:focus에서 입력 스타일이 한 번 깜박이고 포커스가 사라집니다.

답변

1

당신이 .focus()에 집중 할 수 있습니다 :

$('#memberTable tr td').click(function(e) { 
    var $this = $(this); 
    $this.empty(); 

    $('<input />', { 
     type: 'text', 
     id: '', 
     size: 20, 
     value: $this.text() 
    }).appendTo($this).focus(); 
}); 
+0

는 그냥 초점()''와 스타일을 보여주는 것, 입력은 – NestedWeb

+0

@NestedWeb 작동하지 않습니다 : 나를 위해 잘 작동합니다 (약간의 변화가 있음) : http://jsfiddle.net/S4PVY/3/ – Blender

0

을 수동으로 초점을보십시오 :

var input = $('<input type="text" id="" size="20" value="" />'); 

$(this).empty().append(input); 

input.focus(); 
관련 문제