不确定是否有任何本机方法,但这可能用作简单的解决方法。
这个想法是在检测到元素上的点击事件时设置width相应(在给定索引上)元素的样式:<th>.editable
$('.editable').click(function(){
// change the <td> width only if it's less than '.editable-container' width
if($(this).next().width() > $(this).closest('td').width()){
$('th:eq('+$(this).closest('td').index()+')').css('width', $(this).next().width()+15);
}
});
注意:
$(this).next()指向包含输入字段和按钮的.editable-container span元素。✔✖
然后使用可编辑的hidden事件<th>再次将宽度重置为auto:
$('.editable').on('hidden', function() {
$('th:eq('+$(this).closest('td').index()+')').css('width', 'auto');
});
JSFiddle