2012-12-16 144 views
0

我創建了一個PHP foreach循環表;現在我試圖用單擊input替換td中的值。<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();