gpt4 book ai didi

jquery - 在父 td 之外扩展 textarea

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:45 25 4
gpt4 key购买 nike

我有一个表格,我希望能够在其中双击单元格以对其进行编辑。即使我只显示实际表格单元格中的前几个字符,我也想在 textarea 元素内双击显示/编辑全文。

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>

此 fiddle 中的相同代码:https://jsfiddle.net/prxbl/1hw2f0b9/29/

目前的问题:

  1. Textarea 元素应扩展到父元素 td 之外,位于所有元素之上,而不会破坏表格布局。
  2. Textarea 元素不应该是透明的,它应该遮住后面的元素。

非常感谢任何解决这些问题的帮助。

最佳答案

问题1和2都可以通过加上“position: absolute;”来解决在 CSS 中对 .edit-box 进行分类。现在 textarea 元素可以扩展到父容器之外。

关于jquery - 在父 td 之外扩展 textarea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36505131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com