次のコードを試していますが、機能していません。
var option=$('<input type="text" value=""/>');
$(this).append($(option));
$(option).focus();
私も使用しようとしました:
$(this).children().first().focus();
しかし、それも機能していません。
完全な関数は次のとおりです。
var templatestring = "<tr><td class='itemId' style='display:none'></td><td id='tdelement' class='Correct'></td><td id='tdelement' class='Option'></td></td><td id='tdelement' class='Action'><input type='button' value='View' onclick='view(this)'/></td><td id='tdelement' class='Remove'><img src='" + STATIC_URL + "img/delete.jpg' width='20' height='20' align='center'></td></tr>";
var template = $(templatestring);
$("#addoption").button().click(function() {
var newrow = $(template).clone();
$(newrow).children().each(function() {
switch($(this).attr('class')) {
case 'itemId':
$(this).html('');
break;
case 'Option':
var option=$('<input type="text" value=""/>');
$(this).append($(option));
$(this).find('input:text').val('11');
$(option).focus();
break;
case 'Correct':
$(this).html('<input type="radio" class="Answer" name="correct"/>');
break;
case 'Action':
$('input:button', this).val('Add');
break;
}
});
$('#datatable tbody').append(newrow);
});
それが助けになるなら、私はGoogle Chromeを使用しています。