我有一个表格,我希望能够双击单元格以编辑它们。即使我只显示实际表格单元格中的前几个字符,我想在textarea元素内双击显示/编辑全文。展开textarea在父级之外td
textarea元素将保持隐藏状态,直到表格单元格被双击,然后它会在表格单元格顶部可见,直到它再次隐藏时为blur()事件。如果有更好的方法,请告诉我。
$(function() {
$('td.nota').dblclick(function (e) {
e.stopPropagation(); //stop the propagation of the event here
$(this).children().css("display","block");
$(this).children().focus();
//alert('test');
});
});
$('td.nota').children().blur(function(){
$(this).css("display","none");
});
body {
margin: 50px 25px;
}
table {
width: auto !important;
}
.edit-box {
display:none;
float: left;
margin-left: -8px;
margin-top: -28px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="table-responsive">
<table class="table table-bordered table-hover">
<tbody>
<tr>
<td class="text-center"><input type="checkbox" name="selected[]" value="761">
</td>
<td class="text-left nota" id="761" style="max-width: 20ch;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">Lorem ipsum dolor sit amet, consectetur adipiscing elit<textarea class="edit-box" rows="2">Lorem ipsum dolor sit amet, consectetur adipiscing elit</textarea></td>
</tr>
<tr>
<td class="text-center"><input type="checkbox" name="selected[]" value="760">
</td>
<td class="text-left nota" id="760" style="max-width: 20ch;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">Lorem ipsum dolor sit amet, consectetur adipiscing elit<textarea class="edit-box" rows="2">Lorem ipsum dolor sit amet, consectetur adipiscing elit</textarea></td>
</tr>
</tbody>
</table>
</div>
相同的代码,在此琴:https://jsfiddle.net/prxbl/1hw2f0b9/29/
目前存在的问题:
- textarea元素应扩大超越父TD,一切之上,而不会破坏表布局。
- Textarea元素不应该是透明的,它应该掩盖后面的元素。
任何帮助解决这些问题,非常感谢。
请不要编辑问题以包含答案。这对未来的访问者来说这个问题的目的是失败的,而且非常混乱。 –